UNIX:在退出时等待工艺的孩子吗? [英] UNIX: Waiting on process children upon exit?

查看:161
本文介绍了UNIX:在退出时等待工艺的孩子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有使用叉() EXEC其中派生一些子进程C程序()。家长保持的 PID 开发它的孩子的名单。在一段时间后,它会尝试使用ING它们 WNOHANG 并通知他们是否已经终止用户。

Let's say I have a C program which spawns some child processes using fork() and exec(). The parent keeps a list of the pids of its children. Once in a while, it tries waiting on them using WNOHANG and informs the user if they have terminated.

然后程序决定退出。必须我明确然后上剩余的子进程,使他们不成为​​僵尸?根据维基百科:

The program then decides to exit. Must I explicitly kill and then wait on the remaining child processes so that they don't become zombies? According to Wikipedia:

僵尸程序不应该孤立进程相混淆:一个孤儿进程仍在执行的过程,但其父母已经去世,这些不会成为僵尸进程;相反,它们是由init通过(进程ID 1),等待它的孩子。

因此​​,这意味着等待是不必要的。但是,如果该计划的孩子们在等待他们之前就已经成为僵尸,并退出程序?基本上,将父母的子进程谁是僵尸总是正确回收如果父退出?

So this suggests waiting is unnecessary. But what if the program's children have already become zombies, and the program exits before waiting on them? Basically, will a parent's child processes who are zombies always be reclaimed properly if the parent exits?

推荐答案

没有,那是的实际的僵尸进程的定义。的技术上的僵尸进程是已经终止,但仍然在进程表的进程;但是,如果父进程仍然是围绕读取进程表,并注意孩子终止它不是有害的。进程是更有意义的一个的僵尸的,如果没有读取进程表,并造成死去的孩子家长退出被收割。然而,现代的init 应迅速从漫游系统中的任何亡灵儿童preventing长期的僵尸。

No, that is the practical definition of a zombie process. Technically a zombie process is any process that has terminated but is still in the process table; however, it's not harmful if the parent process is still around to read the process table and note that the child terminated. A process is more meaningfully a zombie if the parent exits without reading the process table and causing the dead child to be "reaped". However, modern init should quickly wait on any undead children preventing longstanding zombies from roaming the system.

如果你仔细考虑这一点,就意味着的所有的孩子说终止成为一段时间内的僵尸进程。

If you consider this carefully, it means all child processes that terminate become zombies for some period of time.

UNIX是病态的。

这篇关于UNIX:在退出时等待工艺的孩子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆