Open In App

Program error signals

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

Signals in computers are a way of communication between the process and the OS. When a running program undergoes some serious error then the OS sends a signal to the process and the process further may not execute. Some processes may have a signal handler that does some important tasks before the process leaves the CPU. 
Signal and interrupt are basically the same but a small distinction exists i.e interrupts are generated by the processor and handled by the kernel but signals are generated by the kernel and handled by the process. Error signals generally cause termination of the program and a core dump 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: 

  • SIGFPE – 
    This error signal denotes some arithmetic error that occurred like division by zero, or floating-point error. If a program stores integer data in a location that is then used as a floating-point operation, this causes an “invalid operation” exception as the processor cannot recognize the data as a floating-point value. But this signal does not specify the type of floating-point error. 
     
  • SIGILL – 
    This signal denotes illegal instruction. When a garbage instruction or instruction that a program has no privilege to execute, is executed then this signal is generated. C does not produce illegal instruction so there is no chance of facing such an error signal, as the probable cause may be that the object file may be corrupted. This signal is also generated when a stack overflow occurs. 
     
  • SIGSEGV – 
    The signal is generated when a process tries to access a memory location not allocated to it, like de-referencing a wild pointer which leads to a “segmentation fault”. The signal is only generated when a program goes far from its memory space so that it can be detected by the memory protection mechanism. 
    The name is an abbreviation for “segmentation violation”. 
  • SIGBUS – 
    The name is an abbreviation for “Bus error”. This signal is also produced when an invalid memory is accessed. It may seem to be the same as SIGSEGV but in SIGSEGV, the memory location referenced is valid but in the case of SIGBUS, memory referenced does not exist i.e de-referencing a memory location out of memory space. 
     
  • SIGABRT – 
    If an error itself is detected by the program then this signal is generated using call to abort(). This signal is also used by the standard library to report an internal error. assert() function in c++ also uses abort() to generate this signal. 
     

C++




// Example of 'SIGABRT' error
 
#include <iostream>
using namespace std;
 
int main() {
 
    int arr[5] = {1, 2, 3, 4, 5};
   
    // SIGABRT error
    arr[6] = 6;
   
    return 0;
}
 
// This code is contributed by sarajadhav12052009


Output:

Abort signal from abort(3) (SIGABRT)
  • SIGSYS – 
    This signal is sent to process when an invalid argument is passed to a system call. 
     
  • SIGTRAP – 
    This signal is sent to process when an exception has occurred. This is requested by the debugger to get informed. For example, if a variable changes its value then this will trigger it. 

Refer for – Segmentation Fault (SIGSEGV) vs Bus Error (SIGBUS)
 


Last Updated : 15 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads