Graceful shutdown terminates a process or supervision subtree in a controlled way, allowing final cleanup before exit. A supervisor asks children to stop, and nested supervisors propagate termination through their own trees. section 9.1.6
Apply graceful shutdown with these operational boundaries:
- Enable exit trapping in a GenServer during init/1 when cleanup must run; graceful termination then invokes terminate/2. section 9.1.6
- Set the child specification's shutdown option to a millisecond timeout, :infinity, or :brutal_kill. section 9.1.6
- Expect forceful termination when cleanup exceeds the configured timeout; the default is 5,000 milliseconds for workers and :infinity for supervisors. section 9.1.6
A cleanup-aware worker
Configure a GenServer to trap exits from init/1, then place final cleanup in terminate/2. Its supervisor can wait for that cleanup with shutdown: 5_000, wait indefinitely with :infinity, or skip the graceful phase with :brutal_kill. section 9.1.6
Trace how termination flows from a top-level supervisor through its immediate children and nested supervision subtrees. section 9.1.6



