是否可以通过编程方式更改UNIX进程的可执行文件名称(ucmd)? [英] is it possible to programatically change an executable name (ucmd) of a unix process?
问题描述
是否可以以编程方式更改ps报告的unix进程的可执行文件名称(ucmd)?
Is it possible to programatically change an executable name (ucmd) of a unix process as reported by ps?
unix/POSIX方法会很好,但是Linux特定的解决方案就足够了.
unix/POSIX way would be nice but Linux specific solution would suffice.
我想更改此处报告的内容
I want to change what is reported here
> ps -o ucmd
CMD
zsh
ps
不是这个,这我知道;)
not this, this I know ;)
> ps -o command
COMMAND
zsh
ps -o command
谢谢
P.S.并不是试图创建一个rootkit,只是net-snmp在检查进程时会使用此名称,而从init以及直接从/etc/init.d(etc/rcX.d/SNNname代替只是名字).
P.S. Not trying to create a rootkit, its just that net-snmp looks at this name when checking processes and my program has a different name when called from init and directly from /etc/init.d (etc/rcX.d/SNNname instead of just name).
推荐答案
您可以使用prctl()
的PR_SET_NAME
函数来做到这一点:
You can do this with the PR_SET_NAME
function of prctl()
:
prctl(PR_SET_NAME, (unsigned long)"xyzzy", 0, 0, 0);
但是,/etc/rcX.d/SNNname
应该是启动您的进程的脚本(至a的符号链接),而不是指向进程可执行文件本身的链接.这也可以解决问题.
However, /etc/rcX.d/SNNname
should be a (symlink to a) script that starts your process, not a link to the process executable itself. This would also solve the problem.
这篇关于是否可以通过编程方式更改UNIX进程的可执行文件名称(ucmd)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!