signal -- Define Program Signal Handling

SYNOPSIS

 #include <signal.h>

    /* This typedef is in <signal.h>. */ -->
 typedef void (*_HANDLER)(int);

 _HANDLER signal(int signum, _HANDLER handler);
 

DESCRIPTION

signal defines the action taken when a signal is received by the program. The signum argument is the number of the signal, which should be specified as a symbolic signal name. Refer to the signal names listed in Supported Signals .

The handler argument is the address of the function to be called when the signal occurs. The handler argument can point to a user function, or it can specify one of the two symbolic values SIG_DFL or SIG_IGN. If you specify SIG_IGN, the signal is ignored, if possible; if you specify SIG_DFL, the default action for the signal is taken. (Note that for most signals, the default action is program termination.) Details of what occurs when you specify SIG_DFL or SIG_IGN are provided in the descriptions of the signals. In addition, Tables 5.2 and 5.3 summarize default actions and the results of ignoring signals.

Refer to Handling Signals for a detailed description of how to use signal.

RETURN VALUE

signal returns the address of the previous handler for the signal. If the signal was previously ignored, SIG_IGN is returned; if no action was defined for the signal, SIG_DFL is returned. If the call to signal cannot be honored (for example, if you specify SIG_IGN for a signal that cannot be ignored), the special value SIG_ERR is returned.

CAUTION

When the library discovers a signal with a handler defined by signal, it first restores default signal handling with the following call before it executes the handler you have defined:
 signal(signum, SIG_DFL);
 
Therefore, it is necessary to reissue signal to handle a recurrence of the same signal.

PORTABILITY

The details of signal handling vary widely from system to system. See Using Signals Portably for information on the portable use of signals.

EXAMPLE

  #include <lcsignal.h>
  #include <float.h>

  signal(SIGFPOFL, &overflow_handler);

     /* Perform calculation. */
  .
  .
  .
     /* This function handles a floating-point overflow */
     /* by replacing the result of the computation with */
     /* plus or minus DBL_MAX and allowing the          */
     /* computation to continue.                        */
     /* This example assumes that SIGFPE is not an      */
     /* OpenEdition-managed signal.                     */

  void overflow_handler(int signum)
  {
     FPE_t *info;
     info = siginfo(); /* Get information about signal. */
     if (!info)

           /* If no information is available, force     */
           /*  default handling.                        */
        raise(SIGFPOFL);

        /* Replace result by appropriate large number.  */
     if (*info->result.doublev < 0.0)
        *info->result.doublev = -DBL_MAX;

     else
        *info->result.doublev = DBL_MAX;
  }
 

RELATED FUNCTIONS

sigaction, cosignal

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.