I have a somewhat interesting setup. I have a wrapper script that does some stuff, and launches a child process. I want to be able to do the following:
- have the wrapper script be able to kill the child process and any of its children that it may have created
- Ensure that if the wrapper itself is signaled / killed it will pass it along to the child processes as well
From what I can see there's a bit of a contradiction here. To account for the first requirement, from what I have seen, I need to use killpg on the child processes' process group. This is fine, but it also kills the wrapper script itself since the child has the parent script's process group.
So now if I setpgrp in the child so it gets a separate PG, I can killpg it with its children properly, BUT not I have lost the second requirement ( if the wrapper gets killed it wont go to the child ).
I can manage this problem by registering a signal handler in the wrapper script and passing the signal via killpg as well, however this doesn't work for SIGKILL... which leaves me at a bit of a paradox.
Any possible solutions to this?