In operating system design, signals are a form of IPC that approximate the behaviour of hardware-level interrupts. They work by having the kernel send a number to the program indicating the type of signal. Signal handlers function similarly to interrupt handlers, where the signal pauses the process.
The kernel has default handlers for each signal, which may ignore the signal or terminate the process. If the default handler occurs, the exit code will be 128 + the signal number. Just like interrupts, the process may be interrupted at any point, and may resume after the signal handler exits.
In UNIX systems
Linux signals are listed at this page. For example, some common signals include:
SIGINT
(2): keyboard interrupt (Ctrl + C
).SIGKILL
(9): terminate immediately. Unignorable signal.SIGSEGV
(11): segfault.SIGTERM
(15): terminate.
We can use a few utilities to interact with signals.
kill()
, defined in signal.h — allows us to send a signal to a process or process group.sigaction()
— allows us to define our own signal handler.
The kill <pid>
command line utility sends SIGTERM
to a given process ID. The -9
flag tells kill
to send SIGKILL
instead. kill
uses permission checks to ensure you have “ownership” over a process (which can be circumvented with sudo
).
See also
- The unrelated signal theory