Linux Signals Explained: How Processes Communicate Through Signals
What Linux signals are, how the kernel delivers them, default actions, catchable vs uncatchable signals, signal masks and the signals every developer meets.
Published November 27, 2026
Signals are the oldest and simplest form of inter-process communication in Unix. When you press Ctrl+C, close a terminal, run kill, or a program divides by zero, a signal is involved. Understanding how they are delivered and handled explains graceful shutdowns, zombie processes, and why kill -9 should be your last resort.
The concept
A signal is a small asynchronous notification sent to a process. It carries almost no data, just a number (SIGINT is 2, SIGTERM is 15, SIGKILL is 9). Signals can come from the kernel (a segmentation fault produces SIGSEGV, a child exiting produces SIGCHLD), from the terminal driver (Ctrl+C sends SIGINT to the foreground process group), or from another process via the kill() system call.
When a signal arrives, the kernel marks it pending on the target. The next time that process returns from kernel mode to user mode, the kernel checks pending signals and takes one of three actions: run the default action, ignore the signal, or call the handler function the process registered. Default actions are to terminate, terminate with a core dump, stop, continue, or ignore.
Two signals are special. SIGKILL and SIGSTOP cannot be caught, blocked or ignored, so the kernel acts on them directly. Every other signal can be handled, which is how well-written servers turn SIGTERM into a clean shutdown and SIGHUP into a configuration reload.
How a signal is delivered
Signals you will actually meet
| Signal | No. | Default action | Typical source / meaning |
|---|---|---|---|
| SIGHUP | 1 | Terminate | Terminal closed; daemons often reload config |
| SIGINT | 2 | Terminate | Ctrl+C in the terminal |
| SIGQUIT | 3 | Core dump | Ctrl+\ in the terminal |
| SIGKILL | 9 | Terminate (uncatchable) | Force kill by kernel or kill -9 |
| SIGSEGV | 11 | Core dump | Invalid memory access |
| SIGPIPE | 13 | Terminate | Write to a closed pipe/socket |
| SIGTERM | 15 | Terminate | Polite shutdown request (kill default) |
| SIGCHLD | 17 | Ignore | A child process exited or stopped |
| SIGSTOP / SIGTSTP | 19 / 20 | Stop | Pause (SIGSTOP uncatchable; Ctrl+Z sends SIGTSTP) |
| SIGCONT | 18 | Continue | Resume a stopped process |
Numbers shown are for x86/ARM Linux; they differ on some other architectures, so prefer names.
Signal masks and pending signals
Each thread has a signal mask: a set of signals it is temporarily blocking. A blocked signal is not lost; it stays pending until unblocked. Programs block signals around critical sections so a handler cannot interrupt a half-finished data structure update. Standard signals do not queue: if SIGCHLD arrives three times while blocked, it is delivered once, which is why SIGCHLD handlers must loop on waitpid().
You can see all of this for any process in /proc/PID/status: SigPnd (pending), SigBlk (blocked), SigIgn (ignored) and SigCgt (caught) are bitmasks where bit N-1 represents signal N.
Inspecting a process's signal state
Practical examples
Catch SIGTERM in C
Use sigaction, not signal(), and only do async-signal-safe work in the handler: set a flag.
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
static volatile sig_atomic_t stop = 0;
static void on_term(int sig) { (void)sig; stop = 1; }
int main(void) {
struct sigaction sa = { .sa_handler = on_term };
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGINT, &sa, NULL);
while (!stop) { pause(); }
puts("cleaning up and exiting");
return 0;
}Handle signals in Python
Python runs handlers in the main thread between bytecodes.
import signal, sys, time
def shutdown(signum, frame):
print(f"got {signal.Signals(signum).name}, closing connections")
sys.exit(0)
signal.signal(signal.SIGTERM, shutdown)
signal.signal(signal.SIGHUP, lambda s, f: print("reloading config"))
while True:
time.sleep(1)Handle signals in Node.js
Close the HTTP server so in-flight requests finish before exit.
const server = require('http').createServer((req, res) => res.end('ok')).listen(3000)
process.on('SIGTERM', () => {
console.log('SIGTERM: draining')
server.close(() => process.exit(0))
setTimeout(() => process.exit(1), 10_000).unref() // hard deadline
})Common mistakes
- Doing real work (printf, malloc, locking) inside a C signal handler. Only async-signal-safe functions are allowed; set a flag instead.
- Reaching for kill -9 first. The process gets no chance to flush buffers, remove lock files or close connections.
- Assuming signals queue. Multiple identical standard signals can collapse into one delivery.
- Forgetting that blocking system calls can return EINTR when a signal arrives; use SA_RESTART or retry loops.
- Hard-coding signal numbers in scripts instead of names; numbers vary across architectures.
Key takeaways
- Signals are small asynchronous notifications identified by number and name.
- The kernel delivers pending signals when a process returns to user mode.
- SIGKILL and SIGSTOP cannot be caught; everything else can be handled, ignored or blocked.
- Handle SIGTERM for graceful shutdown and keep handlers minimal.
FAQ
What is the difference between SIGTERM and SIGKILL?
SIGTERM asks the process to exit and can be handled for cleanup. SIGKILL is enforced by the kernel immediately and cannot be caught.
What are real-time signals?
SIGRTMIN through SIGRTMAX are extra signals that do queue, are delivered in order, and can carry a small integer or pointer payload via sigqueue().
Why does a process not die from kill -9?
It is in uninterruptible sleep (state D), usually waiting on disk or NFS I/O, or it is already a zombie waiting for its parent to reap it.