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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Signals in C language
- Communication between two process using signals in C
- Control Signals in 8155 Microprocessor
- Else without IF and L-Value Required Error in C
- Error Handling in C programs
- How to find Segmentation Error in C & C++ ? (Using GDB)
- NULL undeclared error in C/C++ and how to resolve it
- Segmentation Fault (SIGSEGV) vs Bus Error (SIGBUS)
- C program to print a string without any quote (singe or double) in the program
- Hello World Program : First program while learning Programming
- C program to detect tokens in a C program
- Output of C Program | Set 29
- How to compile 32-bit program on 64-bit gcc in C and C++
- Program to compute Log n
- How does a C program executes?
- 8086 program to add two 8 bit BCD numbers
- Splint -- A C program verifier
- 8085 program to add 2-BCD numbers
- Program to check if two strings are same or not
- 8085 program to add two 8 bit numbers
Improved By : Neeraj Kumar 15