std::signal

From Cppreference

Jump to: navigation, search
Defined in header <csignal>

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

Sets the error handler for signal sig. The signal handler can be set so that default handling will occur, signal is ignored, or an user-defined function is called.

When signal handler is set to a function and a signal occurs, it is implementation defined whether signal(sig, SIG_DFL) will be executed immediately before the start of signal handler. Also, the implementation can prevent some implementation-defined set af signals from occurring while the signal handler runs.

If the user defined function returns when handling SIGFPE, SIGILL or SIGSEGV, the behavior is undefined. In most implementations the program terminates.

Contents

[edit] Parameters

sig - the signal to set the signal handler to. It can be an implementation-defined value or one of the following values:
SIGABRT
abnormal termination
(macro constant)
SIGFPE
floating point exception
(macro constant)
SIGILL
invalid instruction
(macro constant)
SIGINT
interactive attention request sent to the program
(macro constant)
SIGSEGV
invalid memory access
(macro constant)
SIGTERM
termination request sent to the program
(macro constant)


handler - the signal handler. This must be one of the following:
  • SIG_DFL macro. The signal handler is set to default signal handler.
  • SIG_IGN macro. The signal is ignored.
  • pointer to a function. The signature of the function must be equivalent to the following:
void fun(int sig);


[edit] Return value

previous signal handler on success or SIG_ERR on failure (setting a signal handler can be disabled on some implementations).

[edit] Example

[edit] See also

raise
runs the signal handler for particular signal
(function)