Open In App

Program error signals

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: 




// 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)

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

Article Tags :