1

I have a server running ubuntu server. It is behind a proxy...I don't know if that makes a difference. But I have found that a couple of processes I've tried, get terminated when I log out of the SSH session. For instance, I have ipython notebook server and a Mongod server processes running on that server. Whenever I logout, both of these processes die even though they are run in the background with &

I have recently discovered the nohud command which works fantastically. However, why is it that I have not encountered this with most servers? Is there some sort of default in unbuntu server that kills all processes by a user when they hangup from SSH? Can I run nohud by default for all processes?

Thank you

1 Answers1

4

Ubuntu processes handle signals the same way that other Linux distributions and Unices do. When an SSH session disconnects, a SIGHUP signal is sent to the session leader process, which would probably be bash.

Bash, in turn, cleans up after itself:

The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to ensure that they receive the SIGHUP. To prevent the shell from sending the SIGHUP signal to a particular job, it should be removed from the jobs table with the disown builtin (see Job Control Builtins) or marked to not receive SIGHUP using disown -h.

If the huponexit shell option has been set with shopt (see The Shopt Builtin), Bash sends a SIGHUP to all jobs when an interactive login shell exits.

disown is a Bash built-in command. nohup is an external command with similar effect.

I don't recommend reconfiguring Bash to not kill all of its child processes (nor do I know how to do that). Rather, a better goal would be to prevent Bash from dying when its TTY disappears. You can use screen, tmux, or mosh to keep Bash alive.

200_success
  • 4,830