Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

C Standard Library – <signal.h>


May 11, 2021 C


Table of contents


C Standard Library - slt;signal.h.gt;

Brief introduction

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

Library variables

Here are the types of variables defined in the header file signal.h:

Serial number Variable & description
1 sig_atomic_t
This is int Type, use as variables in the signal handler.It is an integer type of an object that can be accessed as an atomic entity, even if there is an asynchronous signal, the object can be accessed as an atomic entity.

Library macros

The following are the macros defined in the header file signal.h, which will be used in the following two functions. SIG_ the function of the signal by using the macro with the signal function.

Serial number Macro & Description
1 SIG_DFL
The default signal handler.
2 SIG_ERR
Represents a signal error.
3 SIG_IGN
Ignore the signal.

SIG macros are signal codes that represent a variety of conditions:

Serial number Macro & Description
1 SIGABRT
The program is extremely terminated.
2 SIGFPE
The arithmetic operation is wrong, such as 0 or overflow.
3 SIGILL
Illegal functions, such as illegal instructions.
4 SIGINT
Interrupt signal, such as CTRL-C.
5 SIGSEGV
Illegal access memory, such as accessing the memory cell that does not exist.
6 SIGTERM
The termination request signal is sent to this program.

The library function

Here are the functions defined in the header file signal.h:

Serial number Function & Description
1 void (*signal(int sig, void (*func)(int)))(int)
This function sets a function to process the signal, that is, the signal processing program.
2 int raise(int sig)
This function will cause the generated signal sig .SIG parameters are compatible with SIG macro.