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 which does some important tasks before the process leaves the CPU.
Signal and interrupt are basically 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 causes 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 debugger to know the cause of program termination.
- SIGFPE –
This error signal denotes some arithmetic error that occurred like division by zero, floating point error. If a program stores integer data in a location which 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 which 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 error signal, as the probable cause may be that the object file may be corrupted. This signal is also generated when stack overflow occurs.
- SIGSEGV –
The signal is generated when process tries to access memory location not allocated to it, like de-referencing a wild pointer which leads to “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 same like SIGSEGV but in SIGSEGV, the memory location referenced is valid but in 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 standard library to report an internal error. assert() function in c++ also uses abort() to generate this signal.
- SIGSYS –
This signal is sent to process when an invalid argument is passed to a system call.
- SIGTRAP –
This signal is send to process when an exception is occurred. This is requested by the debugger to get informed. For example, if a variable changes its value then this will trigger it.
- Signals in C language
- Communication between two process using signals in C
- Else without IF and L-Value Required Error in C
- How to find Segmentation Error in C & C++ ? (Using GDB)
- Error Handling in C programs
- Segmentation Fault (SIGSEGV) vs Bus Error (SIGBUS)
- C program to print a string without any quote (singe or double) in the program
- C program to detect tokens in a C program
- How to compile 32-bit program on 64-bit gcc in C and C++
- How does a C program executes?
- Output of C Program | Set 29
- Program to compute Log n
- 8085 program to add 2-BCD numbers
- 8085 program to add two 16 bit numbers
- 8086 program to add two 8 bit BCD numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Neeraj Kumar 15