I have a console application that is running a calculation and I would like to be able to do certain work like saving unsaved data and properly stopping the calculation if the Windows system is going to log off, shut down or restart.
I would like to be able to do something similar to handling the WM_QUERYENDSESSION message in MFC applications - this message is sent by the system to indicate shutdown or logoff.
What I have in my application now is handling interrupt signals, which looks like this:
interface function processBreakSignal ( signum ) ! SIG$INT - CTRL+CSIGNAL !dec$ attributes C :: processBreakSignal integer(4) :: processBreakSignal integer(2) :: signum end function function processTerminationSignal ( signum ) ! SIG$TERM - Termination request !dec$ attributes C :: processTerminationSignal integer(4) :: processTerminationSignal integer(2) :: signum end function end interface integer(4) :: status4 status4 = SIGNALQQ ( SIG$INT, processBreakSignal ) status4 = SIGNALQQ ( SIG$TERM, processTerminationSignal ) status4 = SIGNALQQ ( SIG$ABORT, processTerminationSignal ) integer(4) function processBreakSignal ( signum ) !dec$ attributes C :: processBreakSignal integer(2) :: signum ... processBreakSignal = signum return end
processTerminationSignal is coded in the same way like processBreakSignal.
If my application is running and I press Ctrl+C, everything is OK.
If I press Ctrl+Break, the system (Windows 7 Professional 64-bit) immediately closes my console application's window. I thought Ctrl+C and Ctrl+Break fire the same interrupt type SIG$INT, don't they?
Finally, is any of the interrupt types, e.g. SIG$TERM or SIG$ABORT, supposed to handle system restart/shutdown or logoff? Right now, just like with Ctrl+Break, it does not seems so - logoff or shutdown close the console window immediately.
What can I do to handle system shutdown/restart/logoff?