程序作业管理-背景后台运行管理2


程序作业管理-背景后台运行管理2
 
程序作业管理-背景后台运行管理
http://www.2cto.com/os/201303/192121.html
 
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

相关内容

    暂无相关文章