How to make child process die after parent exits?

后端 未结 24 2174
天涯浪人
天涯浪人 2020-11-22 05:31

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 o

24条回答
  •  庸人自扰
    2020-11-22 06:18

    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.

    Edit: This is Linux-only

提交回复
热议问题