linux进程的前台执行,后台执行和挂起
linux终端执行ping baidu.com会一直打印ping的结果,ctrl+c会结束进程,ctrl+z会挂起进程ctrl+c 结束进程ctrl+z 挂起进程并放入后台jobs显示当前暂停的进程bg %N使第N个任务在后台运行(%前有空格)fg %N使第N个任务在前台运行ctrl+c结束进程想必都知道是强制结束,那么ctrl+z呢,不会结束进程,而只是把...
·
linux终端执行ping baidu.com会一直打印ping的结果,ctrl+c会结束进程,ctrl+z会挂起进程
ctrl+c 结束进程
ctrl+z 挂起进程并放入后台
jobs 显示当前暂停的进程
bg %N 使第N个任务在后台运行(%前有空格)
fg %N 使第N个任务在前台运行
ctrl+c结束进程想必都知道是强制结束,那么ctrl+z呢,不会结束进程,而只是把进程挂起,还有办法可以继续执行,
[king@bogon ~]$ ping baidu.com
PING baidu.com (39.156.69.79) 56(84) bytes of data.
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=128 time=10.1 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=128 time=220 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=3 ttl=128 time=38.4 ms
^Z
[1]+ Stopped ping baidu.com
[king@bogon ~]$ jobs
[1]+ Stopped ping baidu.com
[king@bogon ~]$ fg %1
ping baidu.com
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=4 ttl=128 time=1615 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=5 ttl=128 time=777 ms
64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=7 ttl=128 time=165 ms
^Z
[1]+ Stopped ping baidu.com
[king@bogon ~]$ jobs
[1]+ Stopped ping baidu.com
如上,ctrl+z执行后,ping命令变成stopped,可以通过jobs查看挂起的进程,然后通过fg %1将其带到前台继续执行1是jobs返回的序号,表示第一个job,linux还有一个bg命令可以让他继续在后台执行
[king@bogon ~]$ ping baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=128 time=81.4 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=128 time=5.87 ms
^Z
[1]+ Stopped ping baidu.com
[king@bogon ~]$ bg %1
[1]+ ping baidu.com &
[king@bogon ~]$ 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=128 time=5.58 ms
jobs
[1]+ Running ping baidu.com &
[king@bogon ~]$ 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=4 ttl=128 time=54.7 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=5 ttl=128 time=78.2 ms
fg 64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=6 ttl=128 time=41.9 ms
%1
ping baidu.com
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=7 ttl=128 time=10.0 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=8 ttl=128 time=426 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=9 ttl=128 time=11.4 ms
^C
--- baidu.com ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 13931ms
rtt min/avg/max/mdev = 5.583/79.600/426.910/126.077 ms
如上,ctrl+z执行后,bg %1将其带到后台继续执行,ping输出的同时可以执行其他命令,不过会被输出干扰,jobs看到一个runing进程带&符号,也就是后台运行,fg %1将其带到前台执行就可以通过ctrl+c结束了
如果不想执行挂起的进程,想杀死进程
[king@bogon ~]$ jobs
[1]- Stopped ping baidu.com
[2]+ Stopped ping baidu.com
[king@bogon ~]$ kill %2
[2]- Terminated ping baidu.com
[king@bogon ~]$ jobs
[1]+ Stopped ping baidu.com
ctrl+z后,可以通过top命令查看挂起的进程
也可以通过ps -aux | grep ping从所有进程中过滤ping,
更多推荐
已为社区贡献1条内容
所有评论(0)