#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <sys/prctl.h>
int main()
{
int pid = fork();
if(pid < 0) {
printf("fail to fork\n");
exit(0);
}else if(pid == 0){ //子进程
printf("it is child %d\n", getpid()); //打印PID
prctl(PR_SET_NAME, "test_child"); //设计进程名
while(1){} //死循环
printf("child is done!\n");
} else { //父进程
printf("it is father %d\n", getpid()); //打印PID
prctl(PR_SET_NAME, "test_father"); //设置进程名
printf("father is done\n"); //结束
}
return 0;
}