2012年(48)
分类: LINUX
2012-07-20 11:51:16
有时候,你期望关闭Shell 终端后,运行的作业不会退出,简单地在命令后加&是行不通的,以下总结几种处理方法:
1.NOHUP ------ run a command immune to hangups, with output to a non-tty
eg:
[root@guangxi iWas]# nohup ping laibin.com.cn >/tmp/out.log 2>&1 &
[1] 7921
[root@guangxi iWas]# jobs
[1]+ Running nohup ping laibin.com.cn >/tmp/out.log 2>&1 &
[root@guangxi iWas]#
2. DISOWN ----- Without options, each jobspec is removed from the table of active jobs.
[root@guangxi iWas]# cp -r /mnt/pspch12/iscw/iwas/u0620.46.linux/ .
[1]+ Stopped cp -i -r /mnt/pspch12/iscw/iwas/u0620.46.linux/ .
[root@guangxi iWas]# bg 1
[1]+ cp -i -r /mnt/pspch12/iscw/iwas/u0620.46.linux/ . &
[root@guangxi iWas]# jobs
[1]+ Running cp -i -r /mnt/pspch12/iscw/iwas/u0620.46.linux/ . &
[root@guangxi iWas]# disown -ah
[root@guangxi iWas]# exit
3.Screen
1.create a new screen:
$ screen
or create a new screen running in background
$ screen -dmS
2.do anything you want in this screen
3.you can exit from this screen by "ctrl+a+d" or just close the client sessioneg:
[root@guangxi iWas]# screen -dmS Urumchi
[root@guangxi iWas]# ping laibin.com.cn
PING laibin.com.cn (9.181.64.233) 56(84) bytes of data.
64 bytes from laibin.com.cn (9.181.64.233): icmp_seq=0 ttl=64 time=0.397 ms
64 bytes from laibin.com.cn (9.181.64.233): icmp_seq=1 ttl=64 time=0.311 ms
64 bytes from laibin.com.cn (9.181.64.233): icmp_seq=2 ttl=64 time=1.15 ms
4.restore your screen from any box
check the screen list in your box:
$ screen -list
select the screen you want to restore:
$ screen -r (if only one screen available now)
$ screen -r(restore a specified screen which create by "-d" param )
$ screen -r(restore the screen with specified pid)
eg:
[root@guangxi ~]# screen -list
There is a screen on:
8530.Urumchi (Detached)
1 Socket in /tmp/screens/S-root.[root@guangxi ~]# screen -r Urumchi
ms
64 bytes from laibin.com.cn (9.181.64.233): icmp_seq=15 ttl=64 time=0.186 ms
64 bytes from laibin.com.cn (9.181.64.233): icmp_seq=16 ttl=64 time=0.186 ms
64 bytes from laibin.com.cn (9.181.64.233): icmp_seq=17 ttl=64 time=0.182 ms
4. VNC: jobs which run from VNC won't be stopped even after exit VNC. How about Kill VNC session? (Not sure)