天天看點

shell 中的作業管理指令 fg bg jobs nohup

cat a.sh

#!/bin/bash

for i in `seq 100 `

do

  echo "the script is running"

  sleep 2

done

執行腳本

[root@localhost ~]# ./a.sh 

the script is running

使用ctrl+z 暫停指令 

使用 jobs 可以在目前shell 中看到指令

<a href="https://s5.51cto.com/wyfs02/M02/8C/B4/wKiom1h0yqfB47P-AAAgdNr0uvU764.jpg-wh_500x0-wm_3-wmp_4-s_4145280513.jpg" target="_blank"></a>

使用 fg % 1 可以讓任務在前台運作

<a href="https://s4.51cto.com/wyfs02/M02/8C/B0/wKioL1h0yxWxzwE6AAAkSp_HLos412.jpg-wh_500x0-wm_3-wmp_4-s_178036209.jpg" target="_blank"></a>

使用 bg % 1 可以讓任務在背景運作,使用ctrl+c 終止指令 ,指令也會運作,關閉目前shell 終端即可

<a href="https://s4.51cto.com/wyfs02/M00/8C/B4/wKiom1h0y2LDCQOwAAA9waO6AY8755.jpg-wh_500x0-wm_3-wmp_4-s_4254140503.jpg" target="_blank"></a>

使用nohup 指令運作指令,關閉目前shell 也不影響任務運作

nohup ./a.sh &amp; 

本文轉自 水滴石川1 51CTO部落格,原文連結:http://blog.51cto.com/sdsca/1890839,如需轉載請自行聯系原作者