Easy Tutorial
❮ C Exercise Example28 C Examples Swapping ❯

C Standard Library - <signal.h>

Introduction

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

Library Variables

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

No. Variable & Description
1 sig_atomic_t <br>This is an int type, used as a variable in signal handlers. 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

Below are the macros defined in the signal.h header file, which are used in the following two functions. The SIG_ macros are used with the signal function to define signal functionality.

No. Macro & Description
1 SIG_DFL <br>Default signal handler.
2 SIG_ERR <br>Represents a signal error.
3 SIG_IGN <br>Ignore signal.

The SIG macros represent signal codes for various conditions:

No. Macro & Description
1 SIGABRT <br>Abnormal program termination.
2 SIGFPE <br>Arithmetic operation error, such as division by zero or overflow.
3 SIGILL <br>Illegal function image, such as an illegal instruction.
4 SIGINT <br>Interrupt signal, such as ctrl-C.
5 SIGSEGV <br>Illegal memory access, such as accessing a non-existent memory unit.
6 SIGTERM <br>Termination request signal sent to the program.

Library Functions

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

No. Function & Description
1 void (signal(int sig, void (func)(int)))(int) <br>This function sets a function to handle signals, i.e., a signal handler.
2 int raise(int sig) <br>This function generates the signal sig. The sig parameter is compatible with the SIG macros.
❮ C Exercise Example28 C Examples Swapping ❯