Signals and Signal Handling

Signals are software interrupts which sent to a program to indicate that an important event has occurred. This events can vary from user requests to illegal memory access errors. Some signals, such as the interrupt signal, indicate that a user has asked the program to do something that is not in the usual flow of control. Depending on the source of and the reason for the event being signaled, A Signal can be either synchronously or asynchronously. All signals, whether synchronous or asynchronous, follow the same pattern −

  • The occurrence of a particular event generates a signal.
  • Next, the signal is delivered to a process.
  • The signal must be handled, once delivered.

Illegal memory access and division by 0 are included in Synchronous signal include. If either of these actions are performed by a running program, a signal is generated. This signals are delivered to the same process that performed the operation that caused the signal. This is the reason they are considered as synchronous.

When an event generates a signal external to a running process, that process receives the signal asynchronously. E.g. Such signals include terminating a process with specific keystrokes (such as <control><C>) and having a timer expire. Generally, an asynchronous signal is sent to another process. A Signal may be handled by following one of two possible handlers −

  • A default signal handler
  • A user-defined signal handler

A default signal handler is associated with every signal that the kernel runs when handling that signal. User-defined signal handler can override this default action that is called to handle the signal. Signals are handled in different ways. Some signals (such as changing the size of a window) are simply ignored; others (such as an illegal memory access) are handled by terminating the program.