How bash handles the jobs when logout?
Whether running background jobs are terminated on exit depends on the shell. Bash normally does not do this, but can be configured to for login shells (shopt -s huponexit
). In any case, access to the tty is impossible after the controlling process (such as a login shell) has terminated.
Situations that do always cause SIGHUP
include:
- Anything in foreground when the tty is closed down.
- Any background job that includes stopped processes when their shell terminates (
SIGCONT
andSIGHUP
). Shells typically warn you before letting this happen.
huponexit summary:
On: Background jobs will be terminated with SIGHUP when shell exits
$ shopt -s huponexit$ shopt huponexithuponexit on
Off: Background jobs will NOT be terminated with SIGHUP when shell exits.
$ shopt -u huponexit$ shopt huponexithuponexit off