Using prctl PR_SET_NAME to set a name for a process or thread?

I am trying to use prctl( PR_SET_NAME, "procname", 0, 0, 0)to set a name for a process, when I read the Linux manual about PR_SET_NAME, it looks like it gave the stream a name if I understood it correctly.

Can it be prctlused to set a name for a process? How to set a name for a process?

+4
source share
2 answers

Yes, you can use PR_SET_NAMEin the first argument, and the name as the second argument to set the name of the calling thread (or process). prctlreturns 0on success. Remember, it depends on where you call it prctl. If you call it inside your process, it will change the name of this process and all threads belonging to it. If you call it inside a specific thread, it will only change 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 on Linux, enter:

top

or

ps

To see the name attached to your process id.

+2
source

, , prctl, /proc/pid/status ( ). ps , ps top, argv [0].

argv [0] = "newprocessname"; wil do.

0

All Articles