为什么需要 nohup 而 disown 本身不起作用?

Why is nohup required and disown doesn't work by itself?

将此代码段视为保存在名为 snippet.sh:

的文件中
nohup xmessage HI </dev/null &>/dev/null & disown
sleep 3

从同一目录,执行 xterm -e bash snippet.sh

3 秒后,xterm 应该消失,而 xmessage window 仍然存在。一切都很好。但是,如果 nohup 从片段文件中的命令中删除怎么办?然后 xmessagexterm 一起消失。 bash 文档似乎表明 disown 本身应该足以防止 SIGHUP 被发送:

       The  shell exits by default upon receipt of a SIGHUP.  Before exiting, an interactive shell resends
       the SIGHUP to all jobs, running or stopped.  Stopped jobs are sent  SIGCONT  to  ensure  that  they
       receive the SIGHUP.  To prevent the shell from sending the signal to a particular job, it should be
       removed from the jobs table with the disown builtin (see SHELL BUILTIN COMMANDS below) or marked to
       not receive SIGHUP using disown -h.

所以,问题是,为什么 xmessage window 没有 nohup 就不会流连忘返?

disown足以阻止shell发送信号,但不会阻止其他人。

特别是,shell 是终端的控制进程,在其进程组中有 xmessage,而 POSIX says 在退出时:

If the process is a controlling process, the SIGHUP signal shall be sent to each process in the foreground process group of the controlling terminal belonging to the calling process.