[Previous] [Contents] [Next]

<signal.h>


Include the standard header <signal.h> to specify how the program handles signals while it executes. A signal can report some exceptional behavior within the program, such as division by zero. Or a signal can report some asynchronous event outside the program, such as someone striking an interactive attention key on a keyboard.

You can report any signal by calling raise. Each implementation defines what signals it generates (if any) and under what circumstances it generates them. An implementation can define signals other than the ones listed here. The standard header <signal.h> can define additional macros with names beginning with SIG to specify the values of additional signals. All such values are integer constant expressions >= 0.

You can specify a signal handler for each signal. A signal handler is a function that the target environment calls when the corresponding signal occurs. The target environment suspends execution of the program until the signal handler returns or calls longjmp. For maximum portability, an asynchronous signal handler should only:

Furthermore, in C++, a signal handler should:

If the signal reports an error within the program (and the signal is not asynchronous), the signal handler can terminate by calling abort, exit, or longjmp.

    /* MACROS */
#define SIGABRT <integer constant expression >= 0>
#define SIGFPE <integer constant expression >= 0>
#define SIGILL <integer constant expression >= 0>
#define SIGINT <integer constant expression >= 0>
#define SIGSEGV <integer constant expression >= 0>
#define SIGTERM <integer constant expression >= 0>
#define SIG_DFL <address constant expression>
#define SIG_ERR <address constant expression>
#define SIG_IGN <address constant expression>

    /* TYPES */
typedef i-type sig_atomic_t;

    /* FUNCTIONS */
int raise(int sig);
void (*signal(int sig, void (*func)(int)))(int);

raise

int raise(int sig);

The function sends the signal sig and returns zero if the signal is successfully reported.

sig_atomic_t

typedef i-type sig_atomic_t;

The type is the integer type i-type for objects whose stored value is altered by an assigning operator as an atomic operation (an operation that never has its execution suspended while partially completed). You declare such objects to communicate between signal handlers and the rest of the program.

SIGABRT

#define SIGABRT <integer constant expression >= 0>

The macro yields the sig argument value for the abort signal.

SIGFPE

#define SIGFPE <integer constant expression >= 0>

The macro yields the sig argument value for the arithmetic error signal, such as for division by zero or result out of range.

SIGILL

#define SIGILL <integer constant expression >= 0>

The macro yields the sig argument value for the invalid execution signal, such as for a corrupted function image.

SIGINT

#define SIGINT <integer constant expression >= 0>

The macro yields the sig argument value for the asynchronous interactive attention signal.

signal

void (*signal(int sig, void (*func)(int)))(int);

The function specifies the new handling for signal sig and returns the previous handling, if successful; otherwise, it returns SIG_ERR.

When the target environment calls a signal handler:

SIGSEGV

#define SIGSEGV <integer constant expression >= 0>

The macro yields the sig argument value for the invalid storage access signal, such as for an erroneous lvalue expression.

SIGTERM

#define SIGTERM <integer constant expression >= 0>

The macro yields the sig argument value for the asynchronous termination request signal.

SIG_DFL

#define SIG_DFL <address constant expression>

The macro yields the func argument value to signal to specify default signal handling.

SIG_ERR

#define SIG_ERR <address constant expression>

The macro yields the signal return value to specify an erroneous call.

SIG_IGN

#define SIG_IGN <address constant expression>

The macro yields the func argument value to signal to specify that the target environment is to henceforth ignore the signal.


See also the Table of Contents and the Index.

Copyright © 1992-2006 by P.J. Plauger and Jim Brodie. All rights reserved.

[Previous] [Contents] [Next]