C Standard Library - <signal.h>


Introduction

signal.h The header file defines a variable type sig_atomic_t, two function calls and some macros to handle reporting during program execution of different signals.

Library variables

The following are the variable types defined in the header file signal.h:

Serial numberVariables & Description
1sig_atomic_t
This is the int type, used as a variable in a signal handler . It is an integer type of an object that can be accessed as an atomic entity even in the presence of asynchronous signals.

Library macros

The following are the macros defined in the header file signal.h. These macros will be used in the following two functions. SIG_ Macros are used with the signal function to define the functionality of a signal.

##123
Serial NumberMacro & Description
SIG_DFLDefault signal handler.
SIG_ERR indicates a signal error.
SIG_IGNIgnore the signal.

SIG Macro is used to represent the signal number of the following conditions:

Serial number Macro & Description123456
SIGABRTThe program terminated abnormally.
SIGFPEAn arithmetic operation error occurred, such as division by 0 or overflow.
SIGILLIllegal function image, such as illegal instruction.
SIGINTInterrupt signal, such as ctrl-C.
SIGSEGVIllegal access to memory, such as accessing a non-existent memory unit.
SIGTERMThe termination request signal sent to this program.
Library functions

The following are the functions defined in the header file signal.h:

Serial numberFunction & Description1void (*signal(int sig, void (*func)(int)))(int) 2int raise(int sig)
This function sets a function to handle the signal, that is, the signal handler.
This function will cause the signal
sig to be generated. The sig parameter is compatible with the SIG macro.