后台运行

后台运行的方式

未启动命令时

eg: test.sh

  1. setsid bash test.sh
  2. nohup test.sh &
  3. scren
  4. tmux , tmux ls , tumx a -t 1

命令已启动

ctrl + z 暂停任务
bg 将命令放入后台运行

shopt | grep hup # 为 off # shopt -s huponexit 设置为 on ,exit 会关闭任务
exit # 就能使 命令在后台继续运行 ## 不能直接关闭终端,直接关闭终端 应该是发送 sigkill 信号

附录

写入 ~/.bashrc ,远程连接则开启 tmux

1
2
3
4
if [[ -z "$TMUX" ]] && [ "$SSH_CONNECTION" != "" ]; then      
tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux
exit
fi