Paweł Hajdan Paweł Hajdan - 1 year ago 170
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:

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download