This question is old, and I am still not clear about why.
Original question in 2014:
In a Gnome Terminal tab, I ran
$ nohup chromium-browser &
But when I close the terminal tab, chromium-browser
also exits. Isn't nohup
supposed to prevent that? Gilles said:
nohup and disown both can be said to suppress SIGHUP, but in different ways. nohup makes the program ignore the signal initially (the program may change this). nohup also tries to arrange for the program not to have a controlling terminal, so that it won't be sent SIGHUP by the kernel when the terminal is closed. disown is purely internal to the shell; it causes the shell not to send SIGHUP when it terminates.
So doesn't nohup make chromium-browser ignore SIGHUP?
I am seeing this on other executables, too, such as and Emacs (GUI mode). But not on xeyes.
This is happening on Ubuntu 12.04, 32-bit when the question was posted.
Update in 2015,
Now I am running Ubuntu 14.04, with google-chrome
instead of chromium-browser
installed. Same thing that happened to chromium-browser before also happens to google-chrome now. nohup google-chrome 2>/dev/null &
doesn't save it from being closed when the terminal tab is closed. /usr/bin/google-chrome
is a link to a bash script /opt/google/chrome/google-chrome
. Why does nohup
applied to the bash script not work? How can we make it work on bash scripts? What about Python scripts?
Best Answer
When you close a GNOME Terminal window, a SIGHUP is sent to the shell that it was running. The shell will typically send a SIGHUP to every process group that it knows it created - even ones started with
nohup
- and then exit. If the shell isbash
, it will skip sending a SIGHUP to any process group that the user marked withdisown
.Running a command with
nohup
makes it ignore SIGHUP, but the process can change that. When the disposition of SIGHUP for a process is the default, then if it receives a SIGHUP, the process will be terminated.Linux provides some tools to examine a running process's signal settings.
The chromium-browser shell script does an
exec
of the compiled app, so its process ID remains the same. So to see its signal settings, I rannohup chromium-browser &
and then looked at/proc/$!/status
to see the signal disposition.Those are hex numbers. This shows that SIGHUP is not caught and is not ignored. Only SIGPIPE (the 13th bit in SigIgn) is ignored. I traced this to the following code:
Despite the comment, signals ignored by the parent are not being ignored. A SIGHUP will kill chromium.
The workaround is to do what @xx4h points out: use the
disown
command in your bash so that, if bash has to exit, it does not send SIGHUP to thechromium-browser
process group. You can write a function to do this: