shell jobs查看作业
jobs命令可以查看分配给shell的作业。jobs命令会显示已停止/运行中的作业,以及 它们的作业号和作业中使用的命令。
code
macname@MacdeMacBook-Pro Desktop % cat test.sh #!/bin/bash # Trapping the script exit # trap "echo Goodbye..." EXIT # count=1 while [ $count -le 5 ] do echo "Loop #$count" sleep 1 count=$[ $count + 1 ] done macname@localhost Desktop % macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % nohup ./test.sh & [1] 43495 macname@MacdeMacBook-Pro Desktop % appending output to nohup.out jobs [1] + running nohup ./test.sh macname@MacdeMacBook-Pro Desktop % [1] + done nohup ./test.sh macname@MacdeMacBook-Pro Desktop % jobs macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop % macname@MacdeMacBook-Pro Desktop %
想查看作业的PID,可以在jobs命令中加入-l选项(小写的L)。
macname@MacdeMacBook-Pro Desktop % nohup ./test.sh & [1] 47026 macname@MacdeMacBook-Pro Desktop % appending output to nohup.out macname@MacdeMacBook-Pro Desktop % jobs -l [1] + 47026 running nohup ./test.sh macname@MacdeMacBook-Pro Desktop % [1] + done nohup ./test.sh macname@MacdeMacBook-Pro Desktop %