os/signal
Systemimport "os/signal"Implements access to incoming OS signals for graceful shutdown handling.
Example
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
sig := <-c
fmt.Println("Got signal:", sig)
}Key Types & Functions
NotifyStopResetNotifyContextAbout os/signal
The os/signal package (imported as os/signal) belongs to the System category of Go packages. Implements access to incoming OS signals for graceful shutdown handling.
Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The os/signal package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.
When using os/signal in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.