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

the script is running

the script is running


使用ctrl+z 暂停命令 


使用 jobs 可以在当前shell 中看到命令


wKiom1h0yqfB47P-AAAgdNr0uvU764.jpg-wh_50


使用 fg % 1 可以让任务在前台运行


wKioL1h0yxWxzwE6AAAkSp_HLos412.jpg-wh_50

使用 bg % 1 可以让任务在后台运行,使用ctrl+c 终止命令 ,命令也会运行,关闭当前shell 终端即可


wKiom1h0y2LDCQOwAAA9waO6AY8755.jpg-wh_50


使用nohup 命令运行命令,关闭当前shell 也不影响任务运行


nohup ./a.sh &