Created
April 16, 2025 23:22
-
-
Save nad2000/447b29474263adcdd76b4986c562fc8d to your computer and use it in GitHub Desktop.
Using SIGINT to gracefully shut down a service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/signal" | |
"time" | |
) | |
func main() { | |
ch := make(chan os.Signal, 1) | |
signal.Notify(ch, os.Interrupt) | |
sig := <-ch | |
fmt.Println("Recieved signal:", sig) | |
fmt.Println("Shutting down...") | |
time.Sleep(3 * time.Second) | |
fmt.Println("Shutdown complete") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment