Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 6/24/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Establish Console Event Handlers

Usually, Control-C event handling is not reliable due to the threaded nature of processes executing on the Windows operating systems. Depending on what is happening at the instant a user enters the Control-C, an event handler may or may not get the opportunity to execute.

In any case, there are two ways to establish a handler if you want to do so. You can use the Windows* API routine SetConsoleCtrlHandler directly or you can use SIGNALQQ to establish a handler for the C SIGINT or SIGBREAK signals.

The Intel® Fortran runtime system establishes a console event handler through a call to SetConsoleCtrlHandler as part of its runtime initialization processing. See Default Console Event Handling for a description of this handler's behavior.

If you call SetConsoleCtrlHandler to establish your own event handler, your handler will be called first on console events.

If you establish a handler through SIGNALQQ with SIGINT or SIGBREAK, the C runtime system will establish its own internal handler for console events through a call to SetConsoleCtrlHandler, and it will record your routine as the desired action to take upon occurrence of an event. When an event is delivered to the C runtime handler, it will reset the action for the signal to SIG_DFL and then call your handler routine.

You must call SIGNALQQ again to reset the action to your routine if you want to continue from the control event. Your handler is called with the signal code (either SIGINT or SIGBREAK) as the argument. After your routine returns to the C runtime event handler, the C handler will return the value TRUE to the operating system indicating the event has been handled.