Change process name without changing argv[0] in Linux

家住魔仙堡 提交于 2019-11-27 20:51:14
Wayne

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.

try this:

char *process_name = "aaa\0";
memcpy((void *)argv[0], process_name, sizeof(process_name));

/* explain: The space allocated for argv[0] could be smaller than the name that you want to give and then you will be overwritting some other unrelated memory. argv[0] size could be just 2 and if your process name is "averylongprocessname" you will be overflowing argv[0]. You need to strlen(argv[0]) and use that in memcpy. thx @ecerulm

*/

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