Explain Signal Handling in C++?

Signals are the interrupts that are delivered to a process by the operating system to stop its ongoing task and attend to the task for which the interrupt has been generated.

  • These signals are defined in <csingnal> header file.
  • Signals can also be generated by the operating system on the basis of system or error conditions.

void (*signal (int sig, void (*func)(int)))(int);

SIGABRT (Signal Abort) Abnormal termination of the program, such as a call to abort.

SIGFPE (Signal floating-point exception) An erroneous arithmetic operation, such as a divide by zero or an operation resulting in overflow.

SIGILL (Signal Illegal Instruction) It is used for detecting illegal instruction.

SIGINT (Signal Interrupt) It is used to receipt an interactive program interrupt signal.

SIGSEGV (Signal segmentation Violation) An invalid access to storage.

SIGTERM (Signal Termination) A termination request sent to the program.

SIGHUP (Signal Hang up) Hang Up, it reports that user’s terminal is disconnected. It is used to report the termination of the controlling process.