bg,fg,ctrl+z组合

时间:2022-07-08 08:22:56

使用ctrl + Z 把一个进程挂起

[root@limt ~]# sh Testlsof.sh >111.log
^Z
[1]+ Stopped sh Testlsof.sh > 111.log
[root@limt ~]#
[root@limt ~]# jobs
[1]+ Stopped sh Testlsof.sh > 111.log

使用bg把一个进程放到后台执行

[root@limt ~]# bg %1
[1]+ sh Testlsof.sh > 111.log &
[root@limt ~]#
[root@limt ~]# jobs
[1]+ Running sh Testlsof.sh > 111.log &
[root@limt ~]# ps -ef|grep Testlsof
root 6399 3612 0 11:34 pts/1 00:00:00 sh Testlsof.sh
root 6482 3612 0 11:35 pts/1 00:00:00 grep Testlsof

使用fg把一个进程放到前台执行

[root@limt ~]# fg %1
sh Testlsof.sh > 111.log

需要注意的是使用bg命令把一个进程放到后台后,如果你关闭终端,那么那个进程将被销毁(因为那个shell下打开的所有进程会收到一个SIGHUP信号,默认行为为销毁进程),但是如果你使用exit命令退出终端那么后台进程仍然在运行