linux 怎么关闭终端后程序仍然运行,几种退出Shell终端后进程仍然保持运行的方法...

有时候,你期望关闭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.Screen1.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 session

eg:

[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)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值