How bash handles the jobs when logout?

后端 未结 2 685
粉色の甜心
粉色の甜心 2020-12-25 15:05

As far as I understood from the books and bash manuals is that. When a user logs out from bash all the background jobs that is started by the user will automatically termina

相关标签:
2条回答
  • 2020-12-25 15:47

    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 and SIGHUP). 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 huponexit
      huponexit       on
      
    • Off: Background jobs will NOT be terminated with SIGHUP when shell exits.

      $ shopt -u huponexit
      $ shopt huponexit
      huponexit       off
      
    0 讨论(0)
  • 2020-12-25 16:06

    Only interactive shells kill jobs when you close them. Other shells (for example those you get by using su - username) don't do that. And interactive shells only kill direct subprocesses.

    0 讨论(0)
提交回复
热议问题