Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 recieves 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.

like image 520
notytony Avatar asked Mar 22 '11 23:03

notytony


People also ask

What is the difference between SIGTERM and SIGKILL?

The SIGTERM signal is a generic signal used to cause program termination. Unlike SIGKILL , this signal can be blocked, handled, and ignored. It is the normal way to politely ask a program to terminate. The shell command kill generates SIGTERM by default.

What is the difference among SIGKILL SIGTERM and SIGSTOP?

The SIGHUP signal is also sent to a process if the remote connection is lost or hangs up. The SIGKILL signal is used to abort a process, and the SIGSTOP signal is used to pause a process. The SIGTERM signal is the default signal sent to processes by commands such as kill and pkill when no signal is specified.

What is a SIGKILL?

SIGKILL. (signal 9) is a directive to kill the process immediately. This signal cannot be caught or ignored. It is typically better to issue SIGTERM rather than SIGKILL. If the program has a handler for SIGTERM, it can clean up and terminate in an orderly fashion.

What does SIGTERM mean?

SIGTERM is the signal that is typically used to administratively terminate a process. That's not a signal that the kernel would send, but that's the signal a process would typically send to terminate (gracefully) another process. That's the signal that is sent by default by the kill , pkill , killall ... commands.


2 Answers

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/

like image 96
Chris Marie Avatar answered Oct 04 '22 02:10

Chris Marie


You can't control that by signal; only its parent process can control that, by calling waitpid() or setting signal handlers for SIGCHLD. See SIGCHLD and SA_NOCLDWAIT in the sigaction(2) manpage for details.

Also, what happens to child threads depends on the Linux kernel version. With 2.6's POSIX threads, killing the main thread should cause the other threads to exit cleanly. With 2.4 LinuxThreads, each thread is actually a separate process and SIGKILL doesn't give the root thread a chance to tell the others to shut down, whereas SIGTERM does.

like image 38
geekosaur Avatar answered Oct 04 '22 02:10

geekosaur