Suppose, I launch a parent process, which launches a subprocess, but then the parent receives a SIGINT
. I want the parent to exit, but I don't want the child process to linger and/or become a zombie. I need to make sure it dies.
If I can determine that the child also received a SIGINT
, then it is probably cleaning up on its own. In that case, I'd prefer to briefly wait while it finishes and exits on its own. But if it did not receive a SIGINT
, then I will send it a SIGTERM
(or SIGKILL
) immediately and let the parent proceed with its own cleanup.
How can I figure out if the child recevied the SIGINT
? (Leaving aside the fact that it might not even respond to SIGINT
...) Do I just have to guess, based on whether or not the parent is running in the foreground process group? What if the SIGINT
was sent programmatically, not via Ctrl+C
?
How can I figure out if the child received the SIGINT?
Perhaps you can't. And what should matter to you is if the child handled SIGINT
(it could have ignored it). See my answer to your other question.
However, in many cases, the signal sent by Ctrl C was sent to a process group. Then you might have got that signal too.
In pathological cases, your entire system experiments thrashing and the child process had not even being scheduled yet to process the signal.
I want the parent to exit, but I don't want the child process to linger and/or become a zombie. I need to make sure it dies.
Maybe you want to use somewhere daemon(3) ?
BTW, I don't understand your question, because I have to guess its (ungiven) motivations. Are you caring about job control or implementing a shell? In what concrete cases do you really care that the child got the SIGINT
and what does that mean to you?