I am trying to use prctl( PR_SET_NAME, "procname", 0, 0, 0)
to set name for a process, when I am reading the Linux Manual about the PR_SET_NAME, looks like it set the name for thread if I understand it correctly.
Can prctl
be used to set name for process? How to set name for process?
The prctl system call has been used in the C language to manipulate diverse characteristics of the calling function or process activities. The first parameter of the “prctl” system call defines what has to be done with the initialised values in header.
PR_SET_DUMPABLE (since Linux 2.3. 20) Set the state of the "dumpable" attribute, which determines whether core dumps are produced for the calling process upon delivery of a signal whose default behavior is to produce a core dump.
Yes, you may use PR_SET_NAME
in the first argument and the name as the second argument to set the name of the calling thread(or process). prctl
returns 0
on success. Remember, it depends where you call this prctl
. If you call it inside your process, it will change the name of that process and all of its belonging threads. If you call it inside a specific thread, it will change only the name of that thread.
Example:
int s;
s = prctl(PR_SET_NAME,"myProcess\0",NULL,NULL,NULL); // name: myProcess
Now, if you are running your process in Linux, type:
top
or
ps
To see the name attached to your process id.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With