Change process name in Linux

前端 未结 5 2047
被撕碎了的回忆
被撕碎了的回忆 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:28

    The below code sample would change the name of the process to "Testing".

        #include 
        #include 
        #include 
    
        int main (int argc, char *argv[]) {
        char* temp = (char*) malloc (20);
        strcpy(temp, "Testing");
        temp[7] = 0;
        printf("Argv[0] --> %s\n", argv[0]);
        argv[0] = temp;
        printf("Argv[0] --> %s\n", argv[0]);    
        return 0;
        }
    

    The output of above program is:

    ./a.out

    Argv[0] --> ./a.out

    Argv[0] --> Testing

    The argv[0] contains the name of the process.

提交回复
热议问题