0

For example: We have a process P1 which invokes another process (i.e. script) P2, now P2(script) invokes another process (i.e. script) P3 and now P3 invoke P4. So, if there is an abnormal termination of P1, how can we terminate P2, P3 and P4.

P1 is aware of pid of P2 because P1 invoke P2 via vfork() and then execvpe(). But P1 is not aware about the pid of P3 and P4.

Please suggest how can I kill P2, P3 and P4.

François Andrieux
  • 28,148
  • 6
  • 56
  • 87
  • *how can we* - who are "we" ? A user? Some program? Orphan processes are adopted by `init`. – Eugene Sh. Feb 17 '22 at 20:26
  • Does this answer your question? [How to kill a process tree programmatically on Linux using C](https://stackoverflow.com/questions/15692275/how-to-kill-a-process-tree-programmatically-on-linux-using-c) – kaylum Feb 17 '22 at 20:29
  • 1
    On Linux, you can use [`prctl()`](https://man7.org/linux/man-pages/man2/prctl.2.html) to arrange for a process to get a signal when its parent exits. – Shawn Feb 17 '22 at 20:52
  • 1
    As long as none of the subprocess becomes a session leader (ie, joins another process group), you can just send a signal to the group. – William Pursell Feb 17 '22 at 20:55
  • 1
    https://stackoverflow.com/questions/6548823/use-and-meaning-of-session-and-process-group-in-unix – William Pursell Feb 17 '22 at 20:56

0 Answers0