C Standard Library

C <signal.h> - SIG_ERR



The C <signal.h> SIG_ERR macro is a value of type void (*)(int). When returned by signal(), it indicates that an error has occurred.

Definition in the <signal.h> header file is:

#define SIG_ERR   /* implementation defined */

Example:

The example below shows the usage of SIG_ERR macro constant.

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void signal_handler(int signal) {
  printf("Received signal %d\n", signal);
}

int main(void) {
  //installing 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");
  return EXIT_SUCCESS;

  return 0;
}

The output of the above code will be similar to:

Sending signal 15
Received signal 15
Exit main()

❮ C <signal.h> Library