Linux Signals

Signal delivery, common signals, signal masking, SIGTERM vs SIGKILL, and graceful shutdown patterns.

Overview

Signals are asynchronous notifications sent to a process by the kernel, another process, or the process itself. Linux numbers its signals from 1 to 64: 31 standard signals, then the real-time signals from 32 to 64. Signals interrupt normal execution and invoke a registered handler, the default action (usually terminate or ignore), or are blocked via a signal mask.

Key Signals for Production

A handful of signals cover almost everything you will do in production.

  • SIGTERM (15): requests graceful termination; processes can catch it and clean up.
  • SIGKILL (9): unconditional termination; it cannot be caught, blocked, or ignored.
  • SIGINT (2): Ctrl+C from the terminal.
  • SIGHUP (1): triggers a config reload in daemons.
  • SIGCHLD (17): sent to the parent when a child changes state.
  • SIGUSR1 / SIGUSR2 (10/12): user-defined signals.

Key concepts

  • SIGTERM (15)
  • SIGKILL (9)
  • SIGHUP (1)
  • Signal mask
  • Real-time signals

Interview questions

  • What happens when you run kill -9 on a process vs kill -15? When should you use each?
  • How do you ensure your Docker container shuts down gracefully when Kubernetes drains a node?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio