Am 09.07.2013 um 06:13 schrieb Charles Yin <char...@mazymind.com>:

> see also : 
> http://stackoverflow.com/questions/3360761/how-to-do-a-cleanup-after-sigkill

The answers tell you that

A) SIGKILL ("kill -9") can *not* be caught by a process and hence

B) If you *really* need to do cleanup in such a case you need to have a 
*separate* "housekeeping" process which observes the critical process (e.g. 
with a "known socket" - or you use "stable mutexes" and upon next run of your 
process you can detect that the previous run did not do a proper cleanup)


A) is by design: it is there to really *really* kill a process in the most 
brutal manner (*) a sysadmin could think of and a process being able to catch 
(and possibly ignore!) that signal would defeat its purpose.

There follows that sending a SIGKILL to a process is to be considered "second 
last resort in case everything else failed" (the last resort would be to pull 
the plug) and hence processes can be expected to leave garbage behind (as in 
"it is usually okay, as people killing a process this way are usually aware of 
that fact").


Now what you *can* catch and handle (and even ignore) is the SIGTERM signal 
("kill" without argument, or "kill -15").

Also refer to

  http://major.io/2010/03/18/sigterm-vs-sigkill/

That said, I strongly assume that Qt itself already handles that signal for you 
and hence you should be able to simply react to the appropriate Qt signals 
("last window closed" for instance, if you have a *GUI* application) - 
(probably!) no need to implement your own Unix signal handler (otherwise: try 
it!)

Note: as the appropriate headers and functions are implemented in the standard 
C library I think even on Windows the approach would be the same to catch these 
"Unix signals".


By the way: SIGTERM is the signal sent to a console application when pressing 
CTRL + C (also on Windows).

Cheers,
  Oliver

(*) which can *still* fail, depending on the state the process is in - we all 
know the "reboot your OS" song ;)
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to