简体   繁体   English

Qt应用程序分叉到后台时意外收到HUP信号

[英]Qt app receives HUP signal unexpectedly when forked to background

I have built a Qt app which upon receipt of the HUP signal shuts down nicely (setup like this how to get signals into Qt ). 我构建了一个Qt应用程序,该应用程序在收到HUP信号后会很好地关闭(这样的设置如何将信号输入Qt )。 This works great under Red Had 6, but when I run this app under Ubuntu 14 my app receives the HUP signal immediately (after forking to run in the background) and then shuts down - even though I didn't send a HUP. 这在Red Had 6下效果很好,但是当我在Ubuntu 14下运行此应用程序时,我的应用程序立即收到HUP信号(在派生在后台运行后),然后关闭-即使我没有发送HUP。 Furthermore, this ONLY happens when my app forks and runs in the background - if I run my app in the foreground it does not receive the hup unexpectedly. 此外,仅当我的应用程序在后台运行时才发生这种情况-如果我在前台运行应用程序,则不会意外收到提示。

Is there some other reason that might cause it to receive a HUP signal when daemonized? 还有其他原因可能导致它在守护进程中接收到HUP信号? (And why under one distro but not the other) (为什么要在一个发行版中而不是另一个发行版中)

When daemonizing (forking), the parent process issues a HUP signal upon exit. 进行守护(派生)时,父进程在退出时会发出HUP信号。 For some reason on Red Hat this signal doesn't hit child process until much later. 出于某种原因,在Red Hat上,此信号要等到很久以后才会生效。 On Ubuntu the signal hits the child quickly (or perhaps Ubuntu holds the signal for the child). 在Ubuntu上,信号很快击中孩子(或者Ubuntu会为孩子保持信号)。

Solution is to confirm parent process has terminated and then hook into the HUP signal. 解决方法是确认父进程已终止,然后挂接到HUP信号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM