“孤儿进程”处理问题。
时间:2010-12-06
来源:互联网
本帖最后由 dooros 于 2010-12-06 16:23 编辑
问题源自:《linux内核设计与实现 第二版》 进程章节
父进程在子进程退出之前退出,他的子进程就成了孤儿进程。
孤儿进程的处理方法是给子进程在当前线程组内找一个线程作为父亲,如果不行就让init做他们的父亲。
当前线程组是指子进程的线程组?还是父进程的线程组?
内核原文注释如下:
/*
* When we die, we re-parent all our children.
* Try to give them to another thread in our thread
* group, and if no such member exists, give it to
* the global child reaper process (ie "init")
*/
应该是父进程进程组的其他进程作为此父进程的子进程的父亲吧?
代码如下:
复制代码
代码里有些不明白的地方,希望大家能帮忙讲解下,谢谢了。
不知道这本书上述代码是怎么来的?
此书用的是2.6.10的源代码,我查看了下源代码,如下:
复制代码
这就非常清楚了。
问题源自:《linux内核设计与实现 第二版》 进程章节
父进程在子进程退出之前退出,他的子进程就成了孤儿进程。
孤儿进程的处理方法是给子进程在当前线程组内找一个线程作为父亲,如果不行就让init做他们的父亲。
当前线程组是指子进程的线程组?还是父进程的线程组?
内核原文注释如下:
/*
* When we die, we re-parent all our children.
* Try to give them to another thread in our thread
* group, and if no such member exists, give it to
* the global child reaper process (ie "init")
*/
应该是父进程进程组的其他进程作为此父进程的子进程的父亲吧?
代码如下:
- struct task_struct *p,*reaper=father;
- struct list_head *list;
-
- if(father->exit_signal!=-1) //这句话是父进程是否退出的判断?
- reaper=pre_thread(reaper); //如果父进程退出了,在自己的进程组内找个父亲?
- else
- reaper=child_reaper; //这句话什么作用?
-
- if(reaper==father)
- reaper=child_reaper; //child_reaper是init进程?
-
-
- list_for_each(list,&father->children){
- p=list_entry(list,struct task_struct,sibling);
- reparent_thread(p,reaper,child_reaper); //p是当前进程,reaper是父进程,child_reaper是init进程?这个函数?
- }
不知道这本书上述代码是怎么来的?
此书用的是2.6.10的源代码,我查看了下源代码,如下:
- do {
- reaper = next_thread(reaper);
- if (reaper == father) {
- reaper = child_reaper;
- break;
- }
- } while (reaper->exit_state >= EXIT_ZOMBIE);
作者: dooros 发布时间: 2010-12-06
child_reaper 就是 init 进程吧。
复制代码
- struct task_struct *child_reaper = &init_task;
作者: amarant 发布时间: 2010-12-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28