| Program termination | |||||||||||||||||||||
| |||||||||||||||||||||
| Unreachable control flow | |||||||||||||||||||||
(C23) | |||||||||||||||||||||
| Communicating with the environment | |||||||||||||||||||||
| |||||||||||||||||||||
| Memory alignment query | |||||||||||||||||||||
(C23) | |||||||||||||||||||||
| Signals | |||||||||||||||||||||
| |||||||||||||||||||||
| Signal types | |||||||||||||||||||||
| Non-local jumps | |||||||||||||||||||||
| Types | |||||||||||||||||||||
Defined in header <signal.h> | ||
#define SIG_ERR /* implementation defined */ | ||
A value of typevoid (*)(int). When returned bysignal, indicates that an error has occurred.
#include <stdio.h>#include <stdlib.h>#include <signal.h> void signal_handler(int sig){printf("Received signal: %d\n", sig);} int main(void){/* Install a signal handler. */if(signal(SIGTERM, signal_handler)== SIG_ERR){printf("Error while installing a signal handler.\n");exit(EXIT_FAILURE);} printf("Sending signal: %d\n",SIGTERM);if(raise(SIGTERM)!=0){printf("Error while raising the SIGTERM signal.\n");exit(EXIT_FAILURE);} printf("Exit main()\n");returnEXIT_SUCCESS;}
Output:
Sending signal: 15Received signal: 15Exit main()
| sets a signal handler for particular signal (function)[edit] | |
C++ documentation forSIG_ERR | |