"I ask you, have you ever known what it is to be an orphan?"
2014-05-07 12:25
796 查看
"I ask you, have you ever known what it is to be an orphan?"
/** Determine if a process group is "orphaned", according to the POSIX
* definition in 2.2.2.52. Orphaned process groups are not to be affected
* by terminal-generated stop signals. Newly orphaned process groups are
* to receive aSIGHUP and a SIGCONT.
*
* "I ask you, have you ever known what it is to be an orphan?"
*/
linus 很不客气的质疑的问看代码的人,“爷问你, 你知道啥是orphaned group 吗?!”
int is_orphaned_pgrp(int pgrp) { struct task_struct **p; for (p = &LAST_TASK ; p > &FIRST_TASK ; --p) { if (!(*p) || ((*p)->pgrp != pgrp) || ((*p)->state == TASK_ZOMBIE) || ((*p)->p_pptr->pid == 1)) continue; if (((*p)->p_pptr->pgrp != pgrp) && ((*p)->p_pptr->session == (*p)->session)) return 0; } return(1); /* (sighing) "Often!" */ }
Orphaned Process Groups
When a controlling process terminates, its terminal becomes free and a new session can be established on it. (In fact, another user could login on the terminal.) This could cause a problem if any processes from the oldsession are still trying to use that terminal.
To prevent problems, process groups that continue running even after the session leader has terminated are marked asorphaned processgroups.
When a process group becomes an orphan, its processes are sent a
SIGHUPsignal. Ordinarily, this causes the processes toterminate. However, if a program ignores this signal or establishes ahandler for it
, it can continue running as inthe orphan process group even after its controlling process terminates;but it still cannot access the terminal any more.
这个是GNU给出的解释
http://www.gnu.org/software/libc/manual/html_node/Orphaned-Process-Groups.html
我简单的注释了一下。。。。估计还是很抽象
int is_orphaned_pgrp(int pgrp) //判断是否为一个孤儿进程组 { struct task_struct **p; for (p = &LAST_TASK ; p > &FIRST_TASK ; --p) { if (!(*p) || //如果进程不存在,下一个 ((*p)->pgrp != pgrp) || // 如果进程所处的进程组不是pgrp,下一个 ((*p)->state == TASK_ZOMBIE) || // 进程的状态是zombie,下一个 ((*p)->p_pptr->pid == 1)) //进程parent是init ,说明此时的*p 是这个process group的leader,下一个 continue; if (((*p)->p_pptr->pgrp != pgrp) && //如果父进程所在的组不在pgrp,但是父进程所在的session存在 ((*p)->p_pptr->session == (*p)->session)) return 0; } return(1); /* (sighing) "Often!" */ }
有图有真相
orphan 与否是靠 parent 和child 的关系来维护,鉴别的
假设判断group2 是否是一个 orphaned group
搜索所有在grp2 里面的进程,只要这个grp2里面的任意进程的parent 进程在当前session,且不在当前process group,那么说明这个group和外界还有联系,他就不是orphan group,只有没有联系了,grp2所有的进程的parent 进程都不在group 2之外,这时候,group内的进程没有能通过parent child关系来和外界发生联系,It‘s a orphan group!
陈皓关于孤儿进程的一篇blog(不是孤儿进程组)
http://coolshell.cn/articles/656.html
相关文章推荐
- iOS the file "xxx.app" couldn't be opened because you don't have permission to view it.
- Why is it necessary for an interface to be "declared" abstract?
- the file "xxx.app" couldn't be opened because you don't have permission to view it.
- iOS 报错:没有查看权限the file "xxx.app" couldn't be opened because you don't have permission to view it.
- "Your computer could not be joined to the domain. You have exceeded the maximum number of computer accounts you are allowed to create in this domain. Contact your system administrator to have this limit reset or increased."
- It is said that wars in the 21st century will be fought over water. Do you agree? What do you think can be done now to alleviate
- 安装Visual Studio 2010时提示"The location specified for the help content store is invalid or you do not have access to it".
- The best way to be "right once" is to have the ability to envision what things are going to look like three weeks, three months
- A man speaks truth 3 out of 4 times. He throws a die and reports it to be a 6. What is the probabili
- 【angular】you have to be inside an Angular CLI project in order to use the serve command
- centos 7 The path "" is not a valid path to the 3.10.0-229.el7.x86_64 kernel headers. Would you like to change it?
- Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created.
- [置顶] Android无法启动AVD解决方法出现"The connection to adb is down...You must restart adb and Eclipse."
- IOS开发报错-The file “XXXX” couldn’t be opened because you don’t have permission to view it.
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- Xcode6:The file couldn’t be opened because you don’t have permission to view it
- couldn’t be opened because you don’t have permission to view it.
- Wordpress转移数据表后出现"You do not have sufficient permissions to access this page"的解决方法
- the file couldn't be opened because you don't have permission to view it
- 【iOS开发-101】解决方案:The file * couldn't be opened because you don't have permission to view it