Try this as a three-step process:
kill(-pid, SIGSTOP); kill(-pid, SIGTERM); kill(-pid, SIGCONT);
The first SIGSTOP should put all processes in a stop state. They cannot catch this signal, so this should stop the whole group of processes.
SIGTERM will be queued for the process, but I do not believe that it will be delivered because the processes will be stopped (this is from memory, and I cannot find the link, but I believe that this is true).
SIGCONT will start the processes again, allowing the delivery of SIGTERM. If the slave first receives SIGCONT, the master can still be stopped, so he will not notice that the slave is leaving. When the master receives SIGCONT, SIGTERM will follow, completing it.
I donβt know if this will really work, and it may be an implementation, depending on when all the signals are actually delivered (including SIGCHLD to the main process), but it may be worth a try.
source share