我只是好奇,僵尸进程发生了什么,如果它的父母不在乎等待它。
从APUE:
内核为每个终止进程保留less量的信息…最小
这个信息由进程ID,进程的终止状态组成。
什么是信号(SIGCHLD,SIG_DFL); 意思?
如何干净地杀死python中的subprocess
僵尸进程不能被杀死
僵尸进程出现时,我产卵进程
父母需要使用waitpid()获取这些信息。
但是,如果父母不等孩子退出,会发生什么:
内核是否删除这些信息(当然是没用的)?
或者,它不断收集这个垃圾?
这个实现是特定的吗?
无法清理父进程为init的僵尸进程
开始一个进程,并从Ruby on Rails应用程序中杀死它,而不会离开僵尸进程
叉100同时进行,有时一些进程变成僵尸
运行命令变成僵尸后,Docker容器拒绝被杀死
为什么起源的过程开始作为僵尸在Qt-app。 Linux的
孤立进程是由init自动采用的,它有一个标准的SIGCHLD处理程序,它只是丢弃死进程的任何退出状态。
在你的情况下,如果僵尸进程的父母死亡僵尸孤儿将通过初始化和清理。
下面的代码测试了这个:
#include <stdlib.h> #include <stdio.h> #include <unistd.h> int main() { pid_t child_pid; if (child_pid = fork()) { // fork a child,child will exit straight away char name[128]; sprintf(name,"/proc/%d/stat",child_pid); char line[2048]; // read childs /proc/pid/stat,field 3 will give its status FILE * fp = fopen(name,"r"); while (fgets(line,sizeof(line),fp)) puts(line); fclose(fp); usleep(5000000); // by Now the child will have exited for sure,repeat fp = fopen(name,fp)) puts(line); fclose(fp); // make another child to repeat the process and exit the parent if (!fork()) { usleep(5000000); // both parent and child will have exited by Now fp = fopen(name,"r"); // this should fail because init has already cleaned up the child if (!fp) { perror("fopen"); return -1; } while (fgets(line,fp)) puts(line); fclose(fp); } } return 0; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。