本文共 859 字,大约阅读时间需要 2 分钟。
刚刚写了一个孤儿进程,顺手打印了他的ppid,居然发现不是1,什么鬼??!!!
因为在发现这个结果之前这个进程已经跑了很多遍了,新fork的进程都没有退出,以为是因为这个原因所以结果跟我想的一样。 然后sudo reboot,接着运行发现运行结果孤儿进程的ppid并不是1,ps aux发现这个代替了init进程来接管孤儿进程的进程名字叫做init–user,重启了几回都是这样的,到现在问题还没解决,写博文备存。贴上代码。#include#include #include int creat_orphan_proc(){ pid_t pid; int i; pid = fork(); for(i - 0;i < 3;i++) { if(pid == -1) { printf("creat child error ...\n"); return -1; } else if(pid == 0) { printf("I`m child proc my pid is %d,my parent pid is %d\n",getpid(),getppid()); sleep(3); } else { printf("I`m parent proc my pid is %d,I will exit\n",getpid()); exit(0); } }}int main(){ creat_orphan_proc(); return 0;}
转载地址:http://ppbsi.baihongyu.com/