From what I understand, SIGKILL cannot be caught. This would imply that a process does not have time to kill it's children before the OS destroys it. This can be demonstrated with a shell script.
#! /bin/bash
trap : SIGTERM SIGINT SIGKILL # SIGKILL is pointless.
mplayer video.avi
Killing it with SIGKILL leaves mplayer running.
$ kill -9 $pid
But when using a terminal emulator (xterm, Terminal, …) it's children get killed along with it. How is this possible?
$ mplayer
And kill it:
$ kill -9 $terminal_pid
And mplayer goes down with the ship. Are terminal emulators somehow catching SIGKILL or is there another force at work here?
Best Answer
The process started by
xterm
will be the session leader in control of the terminal.When the terminal goes away, that process automatically receive a SIGHUP signal (followed by a SIGCONT). This is sent by the kernel in a similar way that processes receive SIGINT when you press CTRL-C.
Additionally, a shell may send SIGHUP to some of its children upon exiting (see
disown
in some shells to disable that)