Why did my wget not die after ssh connection loss?
Programs (and scripts) can choose to ignore most signals, except a few like KILL
. The HUP
signal can be caught and ignored if the software so wishes to.
This is from src/main.c
of the wget
sources (version 1.19.2):
/* Hangup signal handler. When wget receives SIGHUP or SIGUSR1, it
will proceed operation as usual, trying to write into a log file.
If that is impossible, the output will be turned off. */
A bit further down the signal handler is installed:
/* Setup the signal handler to redirect output when hangup is
received. */
if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
signal(SIGHUP, redirect_output_signal);
So it looks like wget
is not ignoring the HUP
signal, but it chooses to continue processing with its output redirected to the log file.
Requested in comments: The meaning of the ?
in the TTY
column of the output from ps
in the question is that the wget
process is not any longer associated with a terminal/TTY. The TTY went away when the SSH connection went down.
Simple: wget
does not abort on SIGHUP
. It does on SIGTERM
and SIGINT
, though.
There is nothing on the man
page but if you sent SIGHUP
to a wget
process then you get this in the terminal:
# in a different terminal while wget is running (with PID 12345)
kill -HUP 12345
# in the wget terminal
SIGHUP received.
Redirecting output to 'wget-log'.