Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using prctl PR_SET_NAME to set name for process or thread?

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?

like image 444
ratzip Avatar asked May 26 '15 08:05

ratzip


People also ask

What is prctl used for?

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.

What is Pr_set_dumpable?

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.


1 Answers

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.

like image 167
ImanKh Avatar answered Sep 20 '22 18:09

ImanKh