Change the name of the process in linux

1 The basic principle of modifying the name of the linux process

The linux process uses argv[0] as the name of the process, so it is only necessary to modify the string at argv[0] to modify the name of the linux process.

2 Problems caused by directly modifying argv[0]

If the name process, argv[0] can't be put down, it will step on the following parameters or the following environment variables.

The environment variables of the process are stored immediately after the argv string array.

3 Solutions

First save argv and environment variables, then modify argv[0], and then copy the original content behind argv[0] to the new argv[0].

 

The setproctitle that appears in various c programs is the name of the modified process.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324617709&siteId=291194637