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

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

  •  24-06-2022
  •  | 
  •  

Frage

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

War es hilfreich?

Lösung

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 :)

Andere Tipps

You can try using this:-

pkill -TERM -P 27888

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top