|
|
Log in / Subscribe / Register

+1 on setproctitle

+1 on setproctitle

Posted Oct 8, 2011 9:27 UTC (Sat) by fdr (guest, #57064)
In reply to: +1 on setproctitle by dskoll
Parent article: A Plumber's Wish List for Linux

Color me confused. I have an Ubuntu 10.04 LTS machine, and I have long proctitles:

postgres: archiver process last was 00000003000004B2000000F5

Along with full on user, database, IP(socket) statement-kind information.

Am I missing something?


to post comments

+1 on setproctitle

Posted Oct 8, 2011 10:11 UTC (Sat) by neilbrown (subscriber, #359) [Link]

The bit you are missing is "without mucking with environ[]".

When a process is started, the top of memory contains:

all the args, each nul terminated
an extra nul
all the environment, each entry nul terminated
maybe another nul (not sure).

setproctitle copies new text over the args. If the new text is longer than the old text, it copies over the environment as well. This can be a problem if you later want to use the environment.

The kernel remembers where the args and environment start and end:
unsigned long arg_start, arg_end, env_start, env_end;
(mm_types.h)
proc_pid_cmdline (fs/proc/base.c) knows that if the extra nul isn't there at arg_end, it should look for more text in the env_{start,end} range too.

This feature could be implemented by allowing arg_start, arg_end to be set by some user-space system call. So the process would allocate some memory, fill it with the text to appear in /proc/$pid/cmdline, and "give" that memory to the kernel.

It might be easier to just support a 'write' request on /proc/self/cmdline. Then the kernel would need to allocate a page to store the text, but that isn't a big deal...


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds