36.每日一個Linux命令----先後臺進程切換(fg、bg、jobs、&)

描述:fg 和 bg 命令是進程的先後臺調度命令。linux

操做:shell

Ctrl + c 終止並退出當前前臺命令的執行,回到shellgoogle

Ctrl + z 暫停前臺命令,將該進程放入後臺,回到shellcode

jobs 查看當前在後臺執行的命令,可查看後臺進程號碼進程

& 運行命令時,在命令末尾加上&可以讓命令在後臺執行後臺

fg N 將命令進程號碼爲N的命令進程放到前臺執行,同%Nmap

bg N 將命令進程號碼爲N的命令進程放到後臺執行top

[maple@linux ~]$  ping baidu.com -a >/dev/null &
[1] 12879
[maple@linux ~]$ jobs
[1]+ 
Running                
ping baidu.com -a > /dev/null &
[maple@linux ~]$ ping google.com -a >/dev/null
#Ctrl+Z
[2]+ 
Stopped                
ping google.com -a > /dev/null
[maple@linux ~]$ jobs
[1]- 
Running                
ping baidu.com -a > /dev/null &
[2]+ 
Stopped                
ping google.com -a > /dev/null
[maple@linux ~]$ fg 1
ping baidu.com -a > /dev/null
#Ctrl+Z
[1]+ 
Stopped                
ping baidu.com -a > /dev/null
[maple@linux ~]$ jobs
[1]+ 
Stopped                
ping baidu.com -a > /dev/null
[2]- 
Stopped                
ping google.com -a > /dev/null
[maple@linux ~]$ bg 2
[2]- ping google.com -a > /dev/null &
[maple@linux ~]$ jobs
[1]+ 
Stopped                
ping baidu.com -a > /dev/null
[2]- 
Running                
ping google.com -a > /dev/null &
[maple@linux ~]$ %2
ping google.com -a > /dev/null
#Ctrl+Z
[2]+ 
Stopped                
ping google.com -a > /dev/null
[maple@linux ~]$ jobs
[1]- 
Stopped                
ping baidu.com -a > /dev/null
[2]+ 
Stopped                
ping google.com -a > /dev/null
相關文章
相關標籤/搜索