Stage 3 · Build
Long-Running Daemons & Services
Signal Handling
os/signal, SIGTERM, SIGINT, SIGHUP, context cancellation, and shutdown deadlines.
Signal Overview
Signals are Unix's inter-process communication mechanism. Go programs handle a subset of signals. Understanding signal handling is essential for building reliable daemons and services.
| Signal | Default Action | Typical Use |
|---|---|---|
| SIGINT | Terminate | Ctrl+C in terminal |
| SIGTERM | Terminate | Graceful shutdown request |
| SIGQUIT | Core dump + terminate | Debugging — dumps goroutine stacks |
| SIGHUP | Terminate | Reload configuration |
| SIGUSR1 | Terminate | Custom: reopen log files |
| SIGUSR2 | Terminate | Custom: binary upgrade |
signal.Notify
signal.NotifyContext
SIGHUP Reload
Signaling Goroutines
Shutdown Deadlines
Kubernetes sends SIGTERM, waits for terminationGracePeriodSeconds, then SIGKILL. Your application must handle SIGTERM and shut down cleanly within the grace period. If it does not, SIGKILL forces termination.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.