Search code examples
linuxthread-safetysignals

Difference between SIGKILL SIGTERM considering process tree


What is the difference between SIGTERM and SIGKILL when it comes to the process tree?
When a root thread receives SIGKILL does it get killed cleanly or does it leave it's child threads as zombies?
Is there any signal which can be sent to a root thread to cleanly exit by not leaving any zombie threads ?

Thanks.


Solution

  • If you kill the root process (parent process), this should make orphan children, not zombie children. orphan children are made when you kill a process's parent, and the kernel makes init the parent of orphans. init is supposed to wait until orphan dies, then use wait to clean it up.

    Zombie children are created when a process (not its parent) ends and its parent does not take up its exit status from the process table.

    It sounds to me like you are worried about leaving orphans because by definition, when you kill a zombies parent process, the zombie child itself dies.

    To kill your orphans, use kill -9 , which is the equivalent SIGKILL.

    Here is a more in depth tutorial for killing stuff on linux: http://riccomini.name/posts/linux/2012-09-25-kill-subprocesses-linux-bash/