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

jwillis0720
  • 155
  • 10

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,701
  • 1
  • 24
  • 42
  • Do you know if this is the same behavior with `csh` or `tcsh`? – jwillis0720 Aug 31 '14 at 07:37
  • It should be the same in `csh` or `tcsh`, except that [`nohup` is a builtin command](http://www.tcsh.org/tcsh.html/Builtin_commands.html) in those shells, and `disown` is not. – 200_success Aug 31 '14 at 08:18
  • Hmm, I can't figure it out. When I look at `shopt`, huponexit is set to off, but I can't figure out the other servers I have been apart of seem to never have this behavior. I could just login, run a job, then log off and that job would run until completion provided it was in the background. However, I was not the server admin, and do know if the SIGTERM was overloaded...but thank you for the info – jwillis0720 Aug 31 '14 at 09:00
  • If `huponexit` is enabled, Bash sends a `SIGHUP` to all jobs when an interactive login shell exits. However, when `huponexit` is disabled, it doesn't mean that Bash will not send a `SIGHUP` to any jobs; it means that the default behaviour takes place. – 200_success Aug 31 '14 at 09:08
  • You may have been accustomed to running some processes that chose to "nohup" themselves automatically. – 200_success Aug 31 '14 at 09:09
  • I have used `screen` in the past to keep a proces running in the background after closing the SSH-connection. It works like a charm. When you reconnect, you can list the open screens en regain control over them. Before you leave, you hide the screen again. – BlueCacti Aug 31 '14 at 14:00