博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ubuntu中孤儿进程的父进程pid并不是1??
阅读量:4104 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
python九九乘法表(详解)
查看>>
ESP8266 WIFI数传 Pixhaw折腾笔记
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
python __future__
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(二)
查看>>
pytorch(三)
查看>>
pytorch(四)
查看>>
pytorch(5)
查看>>
pytorch(6)
查看>>
opencv 指定版本下载
查看>>
ubuntu相关
查看>>
C++ 调用json
查看>>