CONSOLE CONTROL HANDLERS
parameter is and is , signals
will be ignored.
flag on (Chapter 2) will
to be treated as keyboard input rather than as a signal.
•The handler routine actually executes as an independent threa d (see
Chapter 7) within the process. The norma l program will continue to operate,
as shown in the next example.
•Raising an exception in the handler will not cause
an exception in the thread
that was interrupted because exceptions apply to threads, not to an entire pro-
cess. If you wish to communicate with the interrupted thread, use a variable,
as in the next example, or a synchroniza tion method (Chapter 8).
There is one other important di stinction between exceptions and si
signal applies to the entire process, whereas an exception applies only to the
thread executing the code where the exception occurs.
identifies the actual signal (or event) and can take on one of the
following five values.
indicates that the sequence was entered from the
indicates that the console window is being closed.
indicates the signal.
indicates that the user is logging off.
indicates that the system is shutting down.
The signal handler can perform cleanup operations just as an exception or ter-
mination handler would. The signal handler should return
to indicate that
the function handled the signal. If the si gnal handler returns
, the next
handler function in the list is executed. The signal handlers are executed in the
reverse order from the way they were set, so that the most recently set handler is
executed first and the system handler is executed last.