使用prctl PR_SET_NAME设置进程或线程的名称? [英] Using prctl PR_SET_NAME to set name for process or thread?
问题描述
我正在尝试使用prctl( PR_SET_NAME, "procname", 0, 0, 0)
为进程设置名称,当我阅读有关PR_SET_NAME的Linux手册时,如果我理解正确的话,它似乎为线程设置了名称.
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.
可以使用prctl
设置进程名称吗?如何为进程设置名称?
Can prctl
be used to set name for process? How to set name for process?
推荐答案
是的,您可以在第一个参数中使用PR_SET_NAME
,并在第二个参数中使用名称来设置调用线程(或进程)的名称. prctl
成功返回0
.请记住,这取决于您在何处将此称为prctl
.如果在进程内部调用它,它将更改该进程及其所有所属线程的名称.如果在特定线程内调用它,它将仅更改该线程的名称.
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.
示例:
int s;
s = prctl(PR_SET_NAME,"myProcess\0",NULL,NULL,NULL); // name: myProcess
现在,如果您正在Linux中运行进程,请输入:
Now, if you are running your process in Linux, type:
top
或
ps
要查看附加到您的进程ID的名称.
To see the name attached to your process id.
这篇关于使用prctl PR_SET_NAME设置进程或线程的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!