Skip to content

40. Signals

A signal is a software interrupt notifying a process that an event occurred — no data transferred, just a notification ("something happened").

Signal Number Meaning
SIGINT2Ctrl+C — interrupt
SIGTERM15Graceful termination request
SIGKILL9Force kill (cannot be caught)
SIGSEGV11Segmentation fault
SIGCHLD17Child stopped/terminated
SIGALRM14Timer expired
SIGPIPE13Broken pipe (reader closed)
SIGHUP1Terminal hangup / reload config
SIGSTOP19Pause (cannot be caught)
SIGCONT18Resume paused process

Handling: default action (e.g., SIGTERM → terminate), a custom registered handler, or explicit ignore. SIGKILL and SIGSTOP can never be caught, blocked, or ignored — this is why kill -9 always works.

Real-world use: graceful shutdown (load balancer sends SIGTERM, server finishes in-flight requests then exits), config reload without restart (SIGHUP, used by nginx), crash logging (SIGSEGV handler logs a stack trace), and zombie prevention (parent's SIGCHLD handler calls wait() to reap the child immediately).

Safety warning: handlers run asynchronously and can interrupt code anywhere, so only async-signal-safe functions are allowed inside them — write(), _exit(), kill() are safe; printf(), malloc(), and any lock are not.