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

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


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.


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


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