I have a parent and a child process where the child is
- spawned (via clone) by a short lived thread of the parent and
- lives in a PID namespace.
What I want to achieve is that the child process is terminated if the parent process is somehow terminated. I understand from this answer that I can set the parent-death signal from the child like so:
prctl(PR_SET_PDEATHSIG, SIGHUP);
However, this already triggers when the parent's thread from which the child was spawned terminates. What I need is a mechanism that only triggers when the parent process terminates.
I tried using waitpid from the child to monitor the parent process but since it is spawned in a PID namespace, the real PID of the parent is not accessible.