Name

signal

Synopsis

Installs a signal handler

#include <signal.h>
void ( *signal( int sig, void (*handler)(int) ) )(int);

The signal() function specifies a function to be executed when the program receives a given signal. The parameter handler is a pointer to a function that takes one argument of type int and has no return value. This pointer may be the address of a function defined in your program, or one of two macros defined in the header file signal.h.

The handler argument works in the following ways (assuming that the call to signal() is successful):

  • If the handler argument is a function pointer, then signal() installs this function as the routine to be called the next time the program receives the signal designated by the integer parameter sig.

  • If the handler argument is equal to the macro SIG_DFL, then the next time the program receives the specified signal, the default signal handler routine is called. The default handler’s action for most signals is to terminate the program.

  • If the handler argument is equal to the macro SIG_IGN, then the specified signal will be ignored.

If the handler argument points to a function in the program, then that function is generally installed as a handler for only one occurrence of the signal, as if the program called signal() with the argument SIG_DFL before calling the handler. To make a handler persistent, you can have your handler function reinstall itself by calling signal() again. Alternatively, the C standard allows implementations to mask the ...

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.