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 1. 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 1:
  • The default can be reset to SIG_IGN, another handler, or the same handler. You can recursively call the signal handler. Once stacked, multiple signal handler calls behave like any other calls. For example, if the action signal to the previous caller is chosen, the control will not be returned to the preceding caller (even if that call is another signal handler) but goes back to the previous caller.
  • The signal() function returns the address of the previous signal handler for the specified signal, and sets the address of the new signal handler.