为什么不要求nohup,但disown本身无法正常工作?

问题描述 投票:0回答:1

将此片段保存为名为snippet.sh的文件:

nohup xmessage HI </dev/null &>/dev/null & disown
sleep 3

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

[3秒钟后,xterm窗口徘徊时xmessage应该消失。一切都很好。但是,如果从片段文件中的命令中删除了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,为什么nohup窗口不会停留?

bash signals nohup
1个回答
0
投票

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

特别是,shell是终端的控制过程,该终端的控制组中的进程为xmessagePOSIX says

如果该过程是控制过程,则将SIGHUP信号发送到属于呼叫过程的控制终端的前台过程组中的每个过程。

© www.soinside.com 2019 - 2024. All rights reserved.