把这个片段看作是保存在一个名为snippet.sh的文件中
nohup xmessage HI </dev/null &>/dev/null & disown
sleep 3从同一个目录中执行xterm -e bash snippet.sh。
3秒后,xterm应消失,而xmessage窗口仍在逗留。一切都很好。但是,如果从代码片段文件中的命令中删除了nohup怎么办?然后,xmessage与xterm一起消失。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就不能继续存在
发布于 2019-10-14 03:21:44
disown足以阻止外壳发送信号,但它不会阻止其他任何人。
尤其是,外壳是终端的控制过程,其进程组为xmessage,退出时为POSIX说:
如果该进程是控制进程,则SIGHUP信号应发送给属于该呼叫进程的控制终端的前台处理组中的每个进程。
https://stackoverflow.com/questions/58369432
复制相似问题