News for hackers. Stuff that matters.
Re:A prog by any other name by umanwizard on Thursday April 28, 2016 @01:17PM (#11590430)
> There is also a setter function, setprogname, which is not to be confused with the slightly different setproctitle. There’s no getter for proctitle, however, unless you count ps.

How's this possible? `ps` has to work somehow.

Re:A prog by any other name by raimue on Thursday April 28, 2016 @01:39PM (#11590588)
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?
Re:A prog by any other name by wiml on Thursday April 28, 2016 @04:40PM (#11591748)
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.