Program Error Signals in C

Program Error Signals in C

Signals in computers are a way of communication between the process and OS(operating system).

Interrupts generated by the processor are handled by the kernel

Signals are generated by the kernel and handled by the process

Error signals generally cause the termination of the program and a file is created named core, which stores the state of the process at the moment of termination. This file can be investigated using the debugger to know the cause of program termination.

Error Signals in C

  • SIGFPE -

    The SIGFPE signal is raised when a computational error occurs. These errors include floating-point overflow, floating-point underflow, and either integer- or floating-point division by 0.

  • SIGILL -

    The SIGILL signal is raised when an attempt is made to execute an invalid, privileged, or ill-formed instruction. SIGILL is usually caused by a program error that overlays code with data or by a call to a function that is not linked to the program load module.

  • SIGSEGV -

    The SIGSEGV signal is raised when the program tries to write/read outside the memory allocated for it or when writing memory which can only be read.

  • SIGBUS -

    occur when a process is trying to access memory that the CPU cannot physically address. In other words, the memory tried to access by the program is not a valid memory address. It caused due to alignment issues with the CPU (eg. trying to read along from an address which isn’t a multiple of 4).

  • SIGABRT -

    The SIGABRT signal is sent to a process to tell it to abort, i.e. to terminate. The signal is usually initiated by the process itself when it calls the abort function of the C Standard Library, but it can be sent to the process from outside like any other signal.

  • SIGSYS -

    The SIGSYS signal is sent to a process when it passes a bad argument to a system call. In practice, this kind of signal is rarely encountered since applications rely on libraries (e.g. libc) to make the call for them.

  • SIGTRAP -

    The SIGTRAP signal is sent to a process when an exception (or trap) occurs: a condition that a debugger has requested to be informed of — for example, when a particular function is executed, or when a particular variable changes value.