如何注销当bash处理工作? [英] How bash handles the jobs when logout?

查看:142
本文介绍了如何注销当bash处理工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我从书本和bash手册了解的是。当用户从庆典注销由用户启动的所有后台作业将自动终止,如果他不使用的nohup或否认。但今天我测试了它:

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 terminate, if he is not using nohup or disown. But today I tested it :


  1. 登录到我的gnome桌面和访问的gnome-terminal。

  2. 有在终端两个选项卡,在一个我创建了一个新的用户名为测试,并记录在作为试验

  1. Logged in to my gnome desktop and accessed gnome-terminal.
  2. There are two tabs in the terminal and in one I created a new user called test and logged in as test

su - test


  • 开始的脚本。

  • started a script.

    cat test.sh
    #!/bin/bash
    sleep 60
    printf "hello world!!"
    exit 0
    
    
    ./test.sh &
    


  • 这之后我登出测试和关闭标签

  • After that I logged out of test and closed the tab

    这是怎么回事?

    推荐答案

    无论是运行后台作业终止退出取决于外壳。巴什一般不会这么做,但可以配置为登录shell(禁用了javascript -s huponexit )。在任何情况下,获得了TTY是不可能控制处理(例如登录壳)终止后

    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.

    该情况总是做事业 SIGHUP 包括:

    Situations that do always cause SIGHUP include:


    • 任何在前台当tty被关闭。

    • 任何包括停止的进程后台作业时,他们的shell终止( SIGCONT SIGHUP )。通常弹这又让发生前发出警告。

    • 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总结:

    huponexit summary:

    $ shopt -s huponexit; shopt | grep huponexit
    huponexit       on
    # Background jobs will be terminated with SIGHUP when shell exits
    
    $ shopt -u huponexit; shopt | grep huponexit
    huponexit       off
    # Background jobs will NOT be terminated with SIGHUP when shell exits
    

    这篇关于如何注销当bash处理工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆