Re:C stdlib isn't threadsafe and even safe Rust didn't save us
by saagarjha on Thursday January 23, 2025 @04:14AM
(#42802225)
A big reason to mutate argv is to change the process's name for tools like top.
[ Parent
| on HN ]
Re:C stdlib isn't threadsafe and even safe Rust didn't save us
by GoblinSlayer on Thursday January 23, 2025 @04:45AM
(#42802432)
For that you write to /proc/self/comm, that's where top gets it from.
Re:C stdlib isn't threadsafe and even safe Rust didn't save us
by gobblegobble2 on Thursday January 23, 2025 @07:15AM
(#42803242)
It may work for top, but not ps among others. The only reliable way is clobbering argv. That's just the way it is. In my opinion, glibc should finally provide setproctitle(), so programs like postgresql or chrome (https://source.chromium.org/chromium/chromium/src/+/main:bas...) don't have to resort to argv hacks.
Re:C stdlib isn't threadsafe and even safe Rust didn't save us
by GoblinSlayer on Friday January 24, 2025 @10:29AM
(#42814018)
There's prctl https://man7.org/linux/man-pages/man2/PR_SET_NAME.2const.htm... that writes to /proc/self/comm