-
-
Save nikos-glikis/4326ba3aba5e01a1bd98efe705f9da1b to your computer and use it in GitHub Desktop.
Golang handle kill signal
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
var gracefulStop = make(chan os.Signal) | |
signal.Notify(gracefulStop, syscall.SIGTERM) | |
signal.Notify(gracefulStop, syscall.SIGINT) | |
go func() { | |
sig := <-gracefulStop | |
fmt.Printf("caught sig: %+v", sig) | |
fmt.Println("Wait for 5 second to finish processing") | |
time.Sleep(5 * time.Second) | |
os.Exit(0) | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bro this is for termination and interrupt signals not task kill signal:))