Configuring the / proc / PID / cmdline stream?

On Linux / NPTL, threads are created as a process.

I see that some of my processes have a strange cmdline line:

cat /proc/5590/cmdline 
hald-addon-storage: polling /dev/scd0 (every 2 sec)

Do you have an idea how I can do this for each thread of my process? This would be very useful for debugging.

/ me now explores the source of HAL

thank

+3
source share
3 answers

If you want to make this portable, there are very few options available that will work with multiple Unix variants.

, , exec argv [0], , , , .

, :

exec -a "This is my cute name" bash

bash "This is my cute name".

C sendmail , , , , .

API setproctitle(3), argv [0] .

+6

argv . :

#include <string.h>
#include <unistd.h>

int
main(int argc, char** argv)
{
    strcpy(argv[0], "Hello, world!");
    sleep(10);
    return 0;
}
+4

Bang .. the code is not so pleasant, the trick is to reuse the environ pointer (here argv_buffer):

memset (argv_buffer[0] + len, 0, argv_size - len);
argv_buffer[1] = NULL;

Any better idea?

Does this work for different threads?

0
source

All Articles