ILE C/C++ Programmer's Guide

Resetting the Signal Action

A signal handling function is called when an exception occurs or when a signal is raised. A handler is defined with the signal() function. The value you assign on the sig parameter is associated with the function referred to on the funct parameter.

When a signal handler is called in a C program, its corresponding signal action is set to SIG_DFL. You must reset the signal action if you want to handle the same signal again. If you do not, the default action is taken on subsequent exceptions. The handling of the signal can be reset from inside or outside the handler by calling signal().

Example:

The following figure shows source code that resets signal handlers.

Figure 180. Resetting Signal Handlers




signal ( SIGINT, &myhandler );
raise ( SIGINT ); /* signal is handled by myhandler. */
...
raise ( SIGINT ); /* signal is handled by SIG_DFL. */
...
signal ( SIGINT, &myhandler );/* reset signal handler to myhandler. */
raise ( SIGINT ); /* signal is handled by myhandler. */

In Figure 180:


[ Top of Page | Previous Page | Next Page | Table of Contents ]