当父进程被“kill -9”杀死时,子进程也会被杀死吗?

发布于 2024-08-06 06:57:28 字数 216 浏览 3 评论 0原文

我的一位同事今天早上告诉我,当他通过“kill -9”杀死 supervisord 时,supervisord 的子进程不是被杀了。

他对此非常确定,但我尝试了很多次,但没有发现这种情况发生。

那么当一个父进程被“kill -9”杀死时,linux会确保它的子进程也被杀死吗?

One of my colleague told me this morning, when he killed supervisord by "kill -9", the subprocesses of supervisord is not killed.

He is quite sure about that, but I tried many times and did not find that happen.

So when a parent process is killed by "kill -9", will linux ensure that it's sub-processes also been killed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

内心旳酸楚 2024-08-13 06:57:28

不,当父进程被杀死时,子进程不一定会被杀死。

然而,如果子进程打开了一个正在写入的管道,而父进程正在从中读取数据,那么当它下次尝试写入该管道时,它将收到一个 SIGPIPE,默认操作是终止它。这就是实践中经常发生的情况。

No, child processes are not necessarily killed when the parent is killed.

However, if the child has a pipe open which it is writing to and the parent is reading from, it will get a SIGPIPE when it next tries to write to the pipe, for which the default action is to kill it. That is often what happens in practice.

水晶透心 2024-08-13 06:57:28

您必须使子进程成为守护进程,以便在父进程被杀死(或死亡)时杀死它们,否则它们将被 init(1) 采用。

You have to make the sub processes daemonic in order to have them killed when the father is killed (or dies), otherwise they are adopted by init(1).

陌伤ぢ 2024-08-13 06:57:28

在 UNIX 上,父进程和子进程的生命周期之间没有强制关系。严格来说,进程只有在调用 exit() 或收到未处理的信号(默认操作是终止)时才会终止。

然而,当用户在该终端上按下 ctrl-C、ctrl-\ 等时,“控制终端”中的整个“前台进程组”可以接收 SIGINT 和 SIGQUIT 等信号。具体行为部分由登录 shell 实现(在 tty 驱动程序的帮助下)。详细信息可能相当复杂:请查看此处此处

On UNIX, there is no enforced relation between parent and child process's lifetimes. Strictly speaking, process will only terminate when they call exit() or receive an unhandled signal for which default action is to terminate.

However, an entire "foreground process group" in a "controlling terminal" can receive signals like SIGINT and SIGQUIT when the user hits ctrl-C, ctrl-\, etc. on that terminal. Specific behaviour is partly implemented by the login shell (with help from the tty driver). Details may be quite complicated: look here and here

神爱温柔 2024-08-13 06:57:28

如果您关闭终端 pid(该进程的父进程 ID),则终端将关闭。当终端关闭时,它的所有进程也会被终止。但是,如果您在 shell 中创建一个子 shell,那么如果您创建任何进程并杀死该进程的 ppid,那么只有该子 shell 及其子进程会成为孤儿。他们的父级成为 init 且 pid 为 1。

[trainee@SIPL ~]$ ps -ef | grep sleep 实习生 3893 3870 0 10:55 pts/1 00:00:00 sleep 4000 实习生 3895 3788 0 10:55 pts/0 00:00:00 grep --color=auto sleep [trainee@SIPL ~]$ Kill - 9 3870 [学员@SIPL ~]$ ps -ef | grep sleep 受训者 3893 1 0 10:55 pts/1 00:00:00 sleep 4000 受训者 3906 3788 0 10:55 pts/0 00:00:00 grep --color=auto sleep

If u close the terminal pid which is the parent process id of the process then terminal is closed. And when terminal is closed then all its processes also gets killed. But if u create a sub shell in shell then if u create any process and kill ppid of that process then only that sub shell kill and their child becomes orphans. Their parent becomes init and pid is 1.

[trainee@SIPL ~]$ ps -ef | grep sleep trainee 3893 3870 0 10:55 pts/1 00:00:00 sleep 4000 trainee 3895 3788 0 10:55 pts/0 00:00:00 grep --color=auto sleep [trainee@SIPL ~]$ kill -9 3870 [trainee@SIPL ~]$ ps -ef | grep sleep trainee 3893 1 0 10:55 pts/1 00:00:00 sleep 4000 trainee 3906 3788 0 10:55 pts/0 00:00:00 grep --color=auto sleep

扛刀软妹 2024-08-13 06:57:28

您只需要知道您想要终止哪个进程或服务即可。就我而言,httpd 是。

killall -9 httpd

它将杀死httpd的所有子进程。

You just need to know which process or service you wanna kill. In my case httpd is.

killall -9 httpd

It will kill all the child processes of httpd.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文