In the absence of a signal handler, does SIGTERM behave identically to SIGKILL

processsignals

Most descriptions of SIGTERM and SIGKILL point out that SIGKILL,

In contrast to SIGTERM and SIGINT, […] cannot be caught or ignored […] (Wikipedia)

Is this the only difference between SIGTERM and SIGKILL? In particular, if a process does not install a SIGTERM handler, is there any difference at all between sending SIGTERM or SIGKILL to the process?

Best Answer

In the absence of any signal configuration, SIGTERM and SIGKILL are in practice equivalent, at least from the killed process’s perspective, as are the other signals whose default action is to terminate a process, including SIGUSR1 and SIGUSR2. As ilkkachu points out, the parent process is informed of the signal which terminated the child process (which is how your shell can distinguish between the signals, and print e.g. “terminated” v. “user-defined signal 1”).

As mentioned on Wikipedia, SIGKILL can’t be caught or ignored, whereas SIGTERM can; note that this means that a process doesn’t need to install a handler for SIGTERM to be ineffective, it can simply block it or ignore it (see sighold(), sigrelse() and sigignore()).

POSIX as a detailed section on the rationale behind signal handling. The Linux signal(7) manpage documents signals in detail too.

Related Question