简体   繁体   中英

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 ). 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. 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? (And why under one distro but not the other)

When daemonizing (forking), the parent process issues a HUP signal upon exit. For some reason on Red Hat this signal doesn't hit child process until much later. On Ubuntu the signal hits the child quickly (or perhaps Ubuntu holds the signal for the child).

Solution is to confirm parent process has terminated and then hook into the HUP signal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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