Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a parent process is killed by "kill -9", will subprocess also be killed?

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?

like image 290
ablmf Avatar asked Sep 29 '09 10:09

ablmf


2 Answers

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.

like image 175
caf Avatar answered Oct 03 '22 02:10

caf


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).

like image 43
drAlberT Avatar answered Oct 03 '22 01:10

drAlberT