我正在尝试在一个命令中终止并暂停 2 个单独的作业。
$ jobs
[1] Running ./jobs2 &
[2] Running ./jobs1 &
[3] Running ./jobs3 &
我正在使用这个命令:
kill ./jobs2 | kill -stop ./jobs1
这应该是最终结果:
$ jobs
[2]+ Stopped ./jobs1
[3]- Running ./jobs3
但是,它没有按预期工作。
答案1
kill -stop %2 && kill %1
例子:
$ sleep 100 &
[1] 2284
$ sleep 200 &
[2] 2325
$ sleep 300 &
[3] 2366
$ jobs
[1] Running sleep 100 &
[2]- Running sleep 200 &
[3]+ Running sleep 300 &
$ kill -stop %2 && kill %1
[1] Terminated sleep 100
[2]+ Stopped sleep 200
$ jobs
[2]+ Stopped sleep 200
[3]- Running sleep 300 &