killing Parent process along with child process using SIGKILL killing Parent process along with child process using SIGKILL unix unix

killing Parent process along with child process using SIGKILL


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

Otherwise, orphans will be linked to init.

Child can ask kernel to deliver SIGHUP (or other signal) when parent dies by specifying option PR_SET_PDEATHSIG in prctl() syscall like this:

prctl(PR_SET_PDEATHSIG, SIGHUP);

See man 2 prctl for details.


Sending the -9 signal (SIGKILL) to a program gives no chance for it to execute its own signal handlers (e.g., your trap statements). That is why the children don't get killed automatically. (In general, -9 gives no chance for the app to clean up after itself.) You have to use a weaker signal to kill it (such as SIGTERM.)

See man 7 signal for details.