在 Linux 中更改进程名称而不更改 argv[0] [英] Change process name without changing argv[0] in Linux
问题描述
我需要修改我的C语言程序的进程名.
我准确地说,这不是我要更改的线程名称.
我想更改我的程序名称,但我找到的唯一解决方案是修改 argv[0]
的值.
我还用 prctl(PR_SET_NAME, "newname")
找到了另一个解决方案,但这个解决方案不起作用.
调用prctl
和修改argv[0]
的区别在于:
- modify
argv[0]
改变/proc/$pid/cmdline
中的信息 - 调用
prctl(PR_SET_NAME)
会改变/proc/$pid/status
中的信息
这意味着您将获得发出 ps -a
和 ps -ax
的进程的不同名称.
如果您在执行 ps 时期望不同参数的进程名称相同,则可以同时执行它们(即,更改 argv[0]
并调用 prctl
).>
希望答案有所帮助.
I need to modify the process name of my program in C language.
I precise, this is not the name of a thread that I want to change.
I want to change the name of my program, but the only solution I found, is to modify the value of argv[0]
.
I also found another solution with prctl(PR_SET_NAME, "newname")
, but this solution doesn't work.
The differences between invoking prctl
and modify argv[0]
are:
- modify
argv[0]
changes information in/proc/$pid/cmdline
- invoking
prctl(PR_SET_NAME)
changes information in/proc/$pid/status
That means you will get difference name of your process issuing ps -a
and ps -ax
.
If you expects same process name for different arguments while executing ps, you can do them both (i.e., change argv[0]
and invoke prctl
).
Hope the answer helps.
这篇关于在 Linux 中更改进程名称而不更改 argv[0]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!