nohup 程序名 & (使程序推到后台运行,即使终端关闭,该程序依然运行)

IshallbeThatIshallbe:~ iamthat$ ps -ef |grep ping
  502   450     1   0  9:30PM ??         0:00.05 ping www.baidu.com
  502   492   475   0  9:32PM ttys000    0:00.00 grep ping
IshallbeThatIshallbe:~ iamthat$ kill -9 502
-bash: kill: (502) - No such process
IshallbeThatIshallbe:~ iamthat$ kill -9 450
IshallbeThatIshallbe:~ iamthat$ ps -ef |grep ping
  502   495   475   0  9:33PM ttys000    0:00.00 grep ping

首先我这里 kill ping 百度的进程 重新演示

 

创建程序:

IshallbeThatIshallbe:~ iamthat$ nohup ping www.baidu.com >> ping.txt &
[1] 507      ---注意这为进程号
IshallbeThatIshallbe:~ iamthat$ 

 

可以看到该程序不断有输出

IshallbeThatIshallbe:~ iamthat$ tail -f ping.txt
64 bytes from 180.97.33.108: icmp_seq=19 ttl=54 time=46.477 ms
64 bytes from 180.97.33.108: icmp_seq=20 ttl=54 time=45.426 ms
64 bytes from 180.97.33.108: icmp_seq=21 ttl=54 time=46.482 ms
64 bytes from 180.97.33.108: icmp_seq=22 ttl=54 time=45.679 ms
64 bytes from 180.97.33.108: icmp_seq=23 ttl=54 time=46.772 ms
64 bytes from 180.97.33.108: icmp_seq=24 ttl=54 time=47.559 ms
64 bytes from 180.97.33.108: icmp_seq=25 ttl=54 time=45.568 ms
64 bytes from 180.97.33.108: icmp_seq=26 ttl=54 time=44.652 ms
64 bytes from 180.97.33.108: icmp_seq=27 ttl=54 time=44.747 ms
64 bytes from 180.97.33.108: icmp_seq=28 ttl=54 time=45.868 ms
64 bytes from 180.97.33.108: icmp_seq=29 ttl=54 time=47.068 ms
64 bytes from 180.97.33.108: icmp_seq=30 ttl=54 time=46.171 ms
64 bytes from 180.97.33.108: icmp_seq=31 ttl=54 time=47.026 ms
64 bytes from 180.97.33.108: icmp_seq=32 ttl=54 time=45.162 ms
64 

 关闭终端,重新打开一个终端

 

Last login: Wed Apr  1 21:37:38 on ttys000
IshallbeThatIshallbe:~ iamthat$ tail -f ping.txt 
64 bytes from 180.97.33.108: icmp_seq=76 ttl=54 time=48.586 ms
64 bytes from 180.97.33.108: icmp_seq=77 ttl=54 time=46.160 ms
64 bytes from 180.97.33.108: icmp_seq=78 ttl=54 time=48.099 ms
64 bytes from 180.97.33.108: icmp_seq=79 ttl=54 time=44.345 ms
64 bytes from 180.97.33.108: icmp_seq=80 ttl=54 time=47.058 ms
64 bytes from 180.97.33.108: icmp_seq=81 ttl=54 time=44.917 ms
64 bytes from 180.97.33.108: icmp_seq=82 ttl=54 time=44.886 ms
64 bytes from 180.97.33.108: icmp_seq=83 ttl=54 time=47.997 ms
64 bytes from 180.97.33.108: icmp_seq=84 ttl=54 time=45.928 ms
64 bytes from 180.97.33.108: icmp_seq=85 ttl=54 time=46.988 ms
64 bytes from 180.97.33.108: icmp_seq=86 ttl=54 time=44.337 ms
64 bytes from 180.97.33.108: icmp_seq=87 ttl=54 time=48.580 ms

 

程序依然在输出在运行。

 

可以看到那个507的进程一直在跑

IshallbeThatIshallbe:~ iamthat$ ps -ef |grep ping
  502   507     1   0  9:36PM ??         0:00.05 ping www.baidu.com
  502   528   520   0  9:38PM ttys000    0:00.00 grep ping
IshallbeThatIshallbe:~ iamthat$ 

 

posted @ 2015-04-01 21:40  IamThat  阅读(340)  评论(0编辑  收藏  举报