14

I sshed to my server and ran wget -r -np zzz.aaa/bbb/ccc and it started working. Then my Internet connection(at my home) got interrupted and I got worried assuming that wget has been hupped because the ssh connection was lost and therefore the terminal had died. But then I sshed to my server an realized that it was still running and putting the output in wget.log and downloading stuff. Can someone please explain to me what might have happened here?

This is what ps gives me:

PID   %CPU %MEM    VSZ    RSS TTY     STAT START   TIME COMMAND
32283  0.6 29.4 179824 147088 ?       S    14:00   1:53 wget -r -np zzz.aaa/bbb/ccc

What it does (question mark) ? mean in the column of tty?

3
  • Note that on a modern system running logind, the default behavior of logind is to kill (SIGTERM) all processes belonging to a user when the user logs out. So this behavior is system-specific. Jan 20, 2018 at 21:02
  • @Dan My system is ubuntu 16.04 Jan 20, 2018 at 21:04
  • 2
    I believe Ubuntu 16.04 is a systemd/logind system, but the Ubuntu default logind.conf explicitly sets KillUserProcesses=no. Jan 20, 2018 at 21:08

2 Answers 2

22

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.

3
  • 1
    I think it would be useful if you also add the meaning of ? in tty. Jan 20, 2018 at 19:18
  • Yes, learned this the hard way. Not all processes die when ssh drops. It is good to know exactly why.
    – Doug
    Jan 20, 2018 at 19:48
  • 2
    Alternately, make a habit of using screen and nothing ever HUPs. Jan 20, 2018 at 21:46
9

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'.
1
  • 1
    Thanks. I think it's better if you also add the kill -HUP pid command to show how one can send SIGHUP to a process. Jan 20, 2018 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .