A simple trick to change a process name in C programming is to do it:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
int main(int argc, char **argv) {
int st = 0;
int pid = fork();
/* copy new name to child process */
if(pid == 0) {
printf("Check my pid: %d\n", getpid());
strcpy(argv[0], "new_name");
sleep(20);
exit(0);
}
wait(&st);
return 0;
}
To see it in action, firstly, compile the program:
gcc -Wall -o test test.c
Now, execute it in background mode:
./test &
Then, check the name of the process through the given pid:
ps -auxww | grep pid
Yeah!!! The key is argv[0] !!!
You can include arguments too, just do it:
strcpy(argv[0],"newprocess -a -x -y");
Now, use your imagination… =]




