C <signal.h> - SIG_DFL, SIG_IGN
The C <signal.h> SIG_DFL, SIG_IGN macros expand into integral expressions that are not equal to an address of any function. The macros define signal handling strategies for signal() function.
Macros | Description |
---|---|
SIG_DFL | (Default handling) The signal is handled by the default action for that particular signal. |
SIG_IGN | (Ignore signal) The signal is ignored and the code execution will continue even if not meaningful. |
Definition in the <signal.h> header file is:
#define SIG_DFL /* implementation defined */ #define SIG_IGN /* implementation defined */
Example:
The example below shows how a signal is handled by default.
#include <signal.h> #include <stdio.h> int main(void) { //using the default signal handler raise(SIGTERM); //this will never be reached printf("Exit main()\n"); return 0; }
The output of the above code will be:
Terminated
Example:
The example below shows how to use SIG_IGN macro function to ignore a signal.
#include <signal.h> #include <stdio.h> int main(void) { //ignoring the signal signal(SIGTERM, SIG_IGN); raise(SIGTERM); printf("Exit main()\n"); return 0; }
The output of the above code will be:
Exit main()
❮ C <signal.h> Library