作业调度(后台运行)
kill
用 kill 命令可以关闭进程 id
sleep
停顿 ,sleep 1 停顿一秒,常用于写脚本的时候
例如 : cmd1
sleep 1
cmd2
sleep 1
cmd3
在cmd1和cmd2之间添加停顿
命令 CTRL +Z 把进程暂停并挂到后台
可以用 jobs命令查看 ,bg id命令开启后台程序 ,fg id命令将后台程序放置前台
编写如下脚本;
用vim 编写一个脚本名叫 hello.sh ,内容是没过10秒写一个 hello
运行脚本 sh hello.sh ,后台挂起程序,再bg执行,那么,就算脚本挂在后台执行,也会显示 hello
[root@yxlll ~]# sh hello.sh ^Z [1]+ Stopped sh hello.sh [root@yxlll ~]# bg 1 [1]+ sh hello.sh & [root@yxlll ~]# hello hello
然后,用fg 可以把脚本挂在前台显示,用 kill可以关闭脚本进程
[root@yxlll ~]# vim hello.sh while true do sleep 10 echo hello done ~ ~ "hello.sh" [New] 5L, 41C written [root@yxlll ~]# sh hello.sh ^Z [1]+ Stopped sh hello.sh [root@yxlll ~]# bg 1 [1]+ sh hello.sh & [root@yxlll ~]# jhello obs [1]+ Running sh hello.sh & [root@yxlll ~]# jobs [1]+ Running sh hello.sh & [root@yxlll ~]# fg 1 sh hello.sh hello ^Z [1]+ Stopped sh hello.sh [root@yxlll ~]# jobs [1]+ Stopped sh hello.sh [root@yxlll ~]# kill %1 [1]+ Stopped sh hello.sh [root@yxlll ~]# jobs [1]+ Terminated sh hello.sh [root@yxlll ~]# jobs