when parent process is killed by 'kill -9', how to terminate child processes [duplicate]

StackOverflow https://stackoverflow.com/questions/18163724

  •  24-06-2022
  •  | 
  •  

Question

kill -9 will send SIGKILL signal to parent process. But SIGKILL can not be caught. So How do parent process terminate child processes?

Was it helpful?

Solution

The parent, once killed via SIGKILL, will just stop existing and thus cannot send signals to its child processes any more. The child process would have to monitor its parent process by itself. When the parent gets killed, the PPID changes to 1 - this might be a helpful to the client to act on its parent being killed. But to "ensure that child process will always be closed with parent process" is not possible from the parents process - that's the nature of SIGKILL. However, if you feel brave you can always hack the source and redefine SIGKILL to something else, but I wouldn't recommend it :)

OTHER TIPS

You can try using this:-

pkill -TERM -P 27888

which will kill all the child processes. Here 27888 is Process Id of the Parent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top