|
|
Log in / Subscribe / Register

+1 on setproctitle

+1 on setproctitle

Posted Oct 7, 2011 20:16 UTC (Fri) by dskoll (subscriber, #1630)
In reply to: +1 on setproctitle by sionescu
Parent article: A Plumber's Wish List for Linux

Yep. 16 characters is too small to be useful. It's nice to get output like this:

postgres 23453 0.2 0.2 1159236 47684 ? Rs 16:05 0:01 postgres: user dbname 127.0.0.1(43135) SELECT


to post comments

±0 on setproctitle

Posted Oct 7, 2011 23:16 UTC (Fri) by jengelh (subscriber, #33263) [Link] (2 responses)

setproctitle you already have, sort of.
void setproctitle(int argc, char **argv, char *title)
{
    strlcpy(argv[0], title, &argv[argc-1][strlen(argv[argc-1])] - argv[0]);
}
or so is how it is currently done, for the glibc-linux platform.

+1 on setproctitle

Posted Oct 8, 2011 15:31 UTC (Sat) by dskoll (subscriber, #1630) [Link] (1 responses)

It's not that easy. Read the source code to some programs that allow changing of the process title (eg, PostgreSQL, Perl, Sendmail.) They all use horrible hacks to get it to work.

+½ on setproctitle

Posted Oct 8, 2011 15:52 UTC (Sat) by jengelh (subscriber, #33263) [Link]

The pgsql code does the same. Plus a handful of extra checks to ensure linearity etc. of course, because it wants to be multi-platform and safe. Now let's rather think about why glibc still does not have the feature (implementing setproctitle via clobbering of argv).

+1 on setproctitle

Posted Oct 8, 2011 9:27 UTC (Sat) by fdr (guest, #57064) [Link] (1 responses)

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?

+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