is it possible to programatically change an executable name (ucmd) of a unix process?

只愿长相守 提交于 2019-12-06 08:59:35

问题


Is it possible to programatically change an executable name (ucmd) of a unix process as reported by ps?

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

thanks

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).


回答1:


You can do this with the PR_SET_NAME function of prctl():

prctl(PR_SET_NAME, (unsigned long)"xyzzy", 0, 0, 0);

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.



来源:https://stackoverflow.com/questions/6841795/is-it-possible-to-programatically-change-an-executable-name-ucmd-of-a-unix-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!