为什么子进程还活着后,父进程在Linux中被打死? [英] Why child process still alive after parent process was killed in Linux?

查看:355
本文介绍了为什么子进程还活着后,父进程在Linux中被打死?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人告诉我,当你杀死在linux父进程,孩子会死。结果
但我对此表示怀疑。所以我写了两篇的bash脚本,其中 father.sh 将调用 child.sh

Someone told me that when you killed a parent process in linux, the child would die.
But I doubt it. So I wrote two bash scripts, where father.shwould invoke child.sh

下面是我的脚本:

现在我跑庆典father.sh ,你可以检查它 PS -alf

Now I run bash father.sh, you could check it ps -alf

然后我杀了 father.sh 杀-9 24588 ,我猜子进程应该是终止,但不幸的是我错了。

Then I killed the father.sh by kill -9 24588, and I guessed the child process should be terminated but unfortunately I was wrong.

谁能解释一下为什么?

Could anyone explain why?

THX

推荐答案

没有,当你独自一人杀死一个过程,它不会杀死孩子。

No, when you kill a process alone, it will not kill the children.

您必须将信号发送到的进程组的,如果你想为一个给定组的所有进程,接收信号

You have to send the signal to the process group if you want all processes for a given group to receive the signal

kill -9 -parentpid

否则,孤儿将被链接到的init ,就表明了你的第三个屏幕截图(儿童的PPID已经成为1)。

Otherwise, orphans will be linked to init, as shown by your third screenshot (PPID of the child has become 1).

这篇关于为什么子进程还活着后,父进程在Linux中被打死?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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