linuxshell命令之作业控制作业控制
内建命令fg可以将后台作业放到前台,&符号使后台作业放到前台运⾏
cat sleep10.sh
#!/bin/bash
sleep 10
执⾏: ./sleep10.sh & #后台执⾏
[1] 44819 #作业号和进程号
fg #将[1]号作业放到前台运⾏
./sleep10.sh
当有多个后台进程时,可以通过fg %作业号的⽅式,将指定的作业
放到前台运⾏
.
/sleep55.sh &
[1] 44839
./sleep10.sh &
[2] 44841
fg %2
./sleep10.sh
下⾯演⽰jobs命令
./sleep55.sh &
[1] 45312
./sleep55.sh &
[2] 45314
.
/sleep10.sh &
[3] 45316
jobs
[1] Running ./sleep55.sh &
[2]- Running ./sleep55.sh &
[3]+ Running ./sleep10.sh &
jobs -l
[1] 45312 Running ./sleep55.sh &
[2]- 45314 Running ./sleep55.sh &
[3]+ 45316 Running ./sleep10.sh &
vi sleep10.sh 按Ctrl+Z
jobs
[1] Running ./sleep55.sh &
[2]- Running ./sleep55.sh &
[4]+ Stopped vi sleep10.sh
再输⼊fg,可以将命令vi sleep10.sh回置到前台
bg命令可以使阻塞的作业转到后台运⾏
./sleep55.sh
^Z #按下ctrl+z组合键,将该作业阻塞
[1]+ Stopped ./sleep55.sh
bg #作业转⼊后台运⾏
[1]+ ./sleep55.sh &
linuxshell脚本怎么运行fg bg, jobs命令只能以作业号为参数来指定作业,这三个命令是不能使⽤进程号的
kill disown wait命令既能以作业号指定作业,也可以⽤进程号指定作业。
vi input &
[1] 45497
[1]+ Stopped vi input
vi loggg &
[2] 45498
[2]+ Stopped vi loggg
jobs
[1]- Stopped vi input
[2]+ Stopped vi loggg
disown %-
bash: warning: deleting stopped job 1 with process group 45497 jobs
[2]+ Stopped vi loggg
disown 45498
bash: warning: deleting stopped job 2 with process group 45498 jobs
cat backls.sh
#!/bin/bash
ls /etc | grep "rc[0-9]" & #列出/etc⽬录下以rc开头,紧跟数字的⽂件echo "The Script quits now"
wait
./backls.sh
The Script quits now
rc0.d
rc1.d
rc2.d
rc3.d
rc4.d
rc5.d
rc6.d
如上,有wait时,直到等到上述执⾏完后,脚本才退出
./backls.sh
The Script quits now
root@ubuntu:/home/cheng/test_program# rc0.d
rc1.d
rc2.d
rc3.d
rc4.d
rc5.d
rc6.d
如上,没有wait时,脚本退出后,还在执⾏后台的命令
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论