SIGSTOP
and SIGKILL
are two signals that cannot be caught and handled by a process. SIGTSTP
is like SIGSTOP
except that it can be caught and handled.
The SIGSTOP
and SIGTSTP
signals stop a process in its tracks, ready for SIGCONT
. When you send that process a SIGTERM
, the process isn't running and so it cannot run the code to exit.
(There are also SIGTTIN
and SIGTTOU
, which are signals generated by the TTY layer when a backgrounded job tries to read or write to the terminal. They can be caught but will otherwise stop (suspend) the process, just like SIGTSTP
. But I'm now going to ignore those two for the remainder of this answer.)
Your CtrlZ sends the process a SIGTSTP
, which appears not to be handled specially in any way by rsyslogd
, so it simply suspends the process pending SIGCONT
or SIGKILL
.
The solution here is also to send SIGCONT
after your SIGTERM
so that the process can receive and handle the signal.
Example:
sleep 999 &
# Assume we got PID 456 for this process
kill -TSTP 456 # Suspend the process (nicely)
kill -TERM 456 # Terminate the process (nicely). Nothing happens
kill -CONT 456 # Continue the process so it can exit cleanly
The documentation for the GNU C Library explains this quite well, I think (my highlighting):
While a process is stopped, no more signals can be delivered to it until it is continued, except SIGKILL
signals and (obviously) SIGCONT
signals. The signals are marked as pending, but not delivered until the process is continued. The SIGKILL
signal always causes termination of the process and can’t be blocked, handled or ignored. You can ignore SIGCONT
, but it always causes the process to be continued anyway if it is stopped. Sending a SIGCONT
signal to a process causes any pending stop signals for that process to be discarded. Likewise, any pending SIGCONT
signals for a process are discarded when it receives a stop signal
kill -15
you'd already sent". – Chris Davies Jul 27 '16 at 14:45SIGTERM
stored as a pending signal when send to aSIGSTOP
'd process, and issued once the process isSIGCONT
'd ? – nohup Jul 27 '16 at 14:54SIGKILL
prevents an app from cleaning up, so usingSIGTERM
is preferable in many (most) cases. – Chris Davies Jul 28 '16 at 13:16