Signals Overview
-
A
signal
is a notification (usually from the kernel) to a process that an event has occurred. Signals are sometimes described assoftware interrupts
. -
Among the types of events that cause the kernel to generate a signal for a process are the following:
- A hardware exception occurred, meaning that the hardware detected a fault condition that was notified to the kernel, which in turn sent a corresponding signal to the process concerned. Example: dividing by 0, referencing a part of memory that is inaccessible
- The user typed one of the terminal special characters that generate signals.
These characters include the interrupt character (usually
Control-C
) and the suspend character (usuallyControl-Z
). - A software event occurred. Example: input became available on a file descriptor, the terminal window was resized, a timer went off, the process’s CPU time limit was exceeded, or a child of this process terminated.
-
Signals fall into two broad categories:
standard
signals: used by the kernel to notify process of events (numbered from 1 to 31 on Linux)realtime
signals
-
Signal flow: -> Generated (from the kernel or process itself) -> Pending -> Delivered to process -> Blocked (if the signal is added to the process’s
signal mask
) -> Arrived at the process -
Upon delivery of a signal, a process carries out one of the following default actions, depending on the signal:
- The signal is
ignored
: discarded by the kernel, has no effect on the process (The process never even knows that it occurred.) - The process is
terminated
(killed). - A
core dump file
is generated, the process isterminated
. A core dump file contains an image of the virtual memory of the process which is used for debugging. - The process is
stopped
- execution of the process is suspended. - Execution of the process is
resumed
after previously being stopped.
- The signal is
-
Instead of accepting the default for a particular signal, a program can change the action that occurs when the signal is delivered (aka setting the
disposition
of the signal). A program can set one of the following dispositions for a signal:- The
default action
should occur. This is useful to undo an earlier change of the disposition of the signal to something other than its default - The signal is
ignored
. This is useful for a signal whose default action would be to terminate the process. - A
signal handler
is executed.
- The