Saturday, July 19, 2014

Algorithms and Me: Signals

Signal is kind of a message sent from kernel or process to one or more processes to notify some event occurrence. Every signal has associated number with it.

Kernel generates signals in cases like encountering illegal instruction or file size limit exceeded or I/O is ready. Example of process sending signal to another process are a child process sending signal to parent to indicate completion of execution.

A process will receive a signal when it is running in user mode. If the receiving process is running in kernel mode, the execution of the signal will start only after the process returns to user mode.

When a signal is received by a process :

1. Process can ignore the signal altogether and it does nothing.

2. Process can accept the signal and appropriate signal handler is executed.

Signal handler can be a default handler or it can be user-defined. When a user-defined handler is used for disposition of a signal, signal is said to be caught.

Note that SIGSTOP and SIGKILL can not be caught or ignore. They will always have default action.

When a signal is accepted, process immediately stops current execution and services the signal.

Once the signal handler is completed, process is resumed again.

0-31 is reserved range for standard signals while range 32 to 64 is used by real time signals.

To show all the signals which are predefined in a system use command kill -l