141 Processes, Signals, and Supervisors
141 Processes, Signals, and Supervisors
Process supervision is about controlling state transitions under uncertainty.
Lifecycle Model
starting -> running -> stopping -> exited
| ^
+-> crash-+
A production supervisor defines what happens in each transition, including restart policy and shutdown deadlines.
Signal Semantics
SIGTERM: request graceful shutdown.SIGINT: interactive stop (often treated similarly).SIGKILL: immediate termination (no cleanup).
Programs should handle SIGTERM/SIGINT by draining in-flight work, closing listeners, and exiting with clear status.
Restart Policy
Blind restart loops can worsen incidents. Prefer bounded backoff with jitter and an upper retry ceiling.
Observability Requirements
A supervisor should emit structured events for:
- process start/exit code
- restart reason
- shutdown duration
- signal received
These events are essential during incident reconstruction.