Change process name in Linux

前端 未结 5 2049
被撕碎了的回忆
被撕碎了的回忆 2021-01-03 21:50

I\'m on Linux and I am forking/execing a new process out of my C spawn application. Is it possible to also change the naming of these new child processes?

I want to

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 22:26

    According to this comment, prctl(PR_SET_NAME) only affects the "short name" of a thread. It has the same effect as writing into /proc/self/comm.

    To change the "long name" (/proc/self/cmdline which is actually used by htop and ps u) you need some ugly hack (which is mentioned in that comment but the link is dead). An example of this kind of hack can be found in Chromium source code: https://cs.chromium.org/chromium/src/services/service_manager/embedder/set_process_title_linux.cc?sq=package:chromium&g=0

提交回复
热议问题