程序作業管理-背景後臺運行管理2

1、nohup
    在ssh執行時,父進程是sshd,如果不要ctrl+c,而直接關掉,而父進程自動變成1。
    會自動生成輸出文件nohup.out,也可以重定向另外文件 >filename 2>&1

2、setsid
    用法和nohup一樣,後面直接跟命令就行,區別是:
    直接顯屏,父ID直接是1,可直接關掉就進入後臺,ctrl+c是取消不了的

3、通過()子shell另類方式,效果同setsid
    [root@pvcent107 ~]# (ping www.ibm.com &)
    [root@pvcent107 ~]# ps -ef |grep www.ibm.com
    root     16270     1  0 14:13 pts/4    00:00:00 ping www.ibm.com
    root     16278 15362  0 14:13 pts/4    00:00:00 grep www.ibm.com

4、&
    這個是放在後臺運行的意思,但還是在shell子程序中,斷開會話時就會結束的

5、disown
    之前已運行在前臺的程序,要放到後臺運行。
    用disown -h jobspec 來使某個作業忽略HUP信號。
    用disown -ah 來使所有的作業都忽略HUP信號。
    用disown -rh 來使正在運行的作業忽略HUP信號。

    如果提交命令時已經用“&”將命令放入後臺運行,則可以直接使用“disown”
    如果提交命令時未使用“&”將命令放入後臺運行,可使用 CTRL-z 和“bg”將其放入後臺,再使用“disown”

    disown 示例               
    [root@pvcent107 build]# cp -r testLargeFile largeFile &
    [1] 4825
    [root@pvcent107 build]# jobs
    [1]+  Running                 cp -i -r testLargeFile largeFile &
    [root@pvcent107 build]# disown -h %1
    [root@pvcent107 build]# ps -ef |grep largeFile
    root      4825   968  1 09:46 pts/4    00:00:00 cp -i -r testLargeFile largeFile
    root      4853   968  0 09:46 pts/4    00:00:00 grep largeFile

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章