nohup 和 ">& nohup.out &" 有什么区别?

Yan*_*ang 5 bash shell nohup

nohup 使进程对 shell 的 SIGHUP 免疫,但即使我从我的 shell 运行它:

bash -c 'while true; do sleep 1; date; done' >& nohup.out &
Run Code Online (Sandbox Code Playgroud)

然后注销并重新登录,bash 仍在运行并向 nohup.out 生成输出。有什么区别吗?仅仅依靠重定向在任何方面都不那么可靠吗?

Bea*_*ano 5

在 bash 后台作业不需要受nohup保护

根据您的 bash 版本,可以更改行为。在手册页的信号部分

如果 huponexit shell 选项已使用 shopt 设置,则 bash 会在交互式登录 shell 退出时向所有作业发送 SIGHUP。

huponexit选项默认为关闭