Paweł Hajdan Paweł Hajdan - 2 months ago 50x
C Question

How to make child process die after parent exits?

Suppose I have a process which spawns exactly one child process. Now when the parent process exits for whatever reason (normally or abnormally, by kill, ^C, assert failure or anything else) I want the child process to die. How to do that correctly?

Some similar question on stackoverflow:

Some similar question on stackoverflow for Windows:


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


See man 2 prctl for details.

Edit: This is Linux-only