3 ms·
On Linux, reading /proc/<pid>/cmdline literally asks the kernel to reach into the target process's address space and fish out its argv[0]. This, erm... has some
by willglynn 8y ago
On Linux, reading /proc/<pid>/cmdline literally asks the kernel to reach into the target process's address space and fish out its argv[0]. This, erm... has some corner cases:
https://github.com/torvalds/linux/blob/v4.20/fs/proc/base.c#L333-L349 https://github.com/torvalds/linux/blob/v4.20/fs/proc/base.c#...
https://github.com/torvalds/linux/blob/v4.20/fs/proc/base.c#L229-L312 https://github.com/torvalds/linux/blob/v4.20/fs/proc/base.c#...
Changing the `ps` output in a cross platform way requires a number of platform-dependent strategies, e.g. how PostgreSQL does it:
https://github.com/postgres/postgres/blob/REL_11_1/src/backend/utils/misc/ps_status.c#L38-L57 https://github.com/postgres/postgres/blob/REL_11_1/src/backe...
- dualbus 8y agoAwesome, thank you! This is super useful. I stand corrected.