Bash – Why are background jobs started by the shell living longer than the parent shell and controlling terminals

bashnohupshellterminal

It is commonly said that "&" puts the process into background execution, but that process would be killed when terminal is closed. But from what I see, everything I sent into background was continuing to be active long after I close the terminal. For example:

$ tail -f /var/log/messages/ &

That process would continue to run, even if there are no other process under the user that launched it, and all terminals are long gone. Why is that?

Best Answer

Just a guess (this is bash specific): the documentation for the huponexit shell option says

If set, Bash will send SIGHUP to all jobs when an interactive login shell exits

On my system, it does not seem to be set by default. You can check with

shopt -p huponexit

If the output includes -u, it is unset.

Related Question