Linux在后台运行脚本
setsid:创建一个新的 会话(session),并让指定的程序在该会话中运行
作用:让进程完全脱离当前终端(TTY)的控制,即使关闭终端或退出 Shell,进程也不会被终止。
- 使用&
1 ./test.sh & 2 免疫:Ctrl+C 3 退出:关闭终端
- 使用nohup
1 nohup ./test.sh 2 免疫:关闭终端 3 退出:Ctrl + C
- 使用nohup......&
1 nohup ./test.sh > log.txt 2>&1 & 2 免疫:关闭终端、Ctrl+C 3 退出:kill
本文来自博客园,作者:Fēngwèi,转载请注明原文链接:https://www.cnblogs.com/fengwei-blogs/p/18825182

浙公网安备 33010602011771号