setproctitle() is only for the current process. It is a system-specific interface implemented in libc (in OpenBSD/FreeBSD a sysctl() to set the memory address where the string is stored).
ps(1) examines other processes and again uses a system-specific interface to the kernel to retrieve all information about other processes (using kvm(3) on OpenBSD/FreeBSD).
Re:A prog by any other name
by umanwizard on Thursday April 28, 2016 @03:16PM
(#11591261)
I see. So you could use the same kvm API to get all the proctitles (assuming you're on a bsd), and then filter it yourself to find the one for the current process, right?
Classically, tools like ps worked by opening /dev/kmem, reading the symbol list from /vmunix or wherever, and chasing data structures in kernel memory a bit like a debugger might.
These days there is usually a getter for proctitle in the form of the /proc filesystem, sysctls, etc.
How's this possible? `ps` has to work somehow.