Skip to content

Instantly share code, notes, and snippets.

@nikos-glikis
Created March 26, 2019 16:44
Show Gist options
  • Save nikos-glikis/4326ba3aba5e01a1bd98efe705f9da1b to your computer and use it in GitHub Desktop.
Save nikos-glikis/4326ba3aba5e01a1bd98efe705f9da1b to your computer and use it in GitHub Desktop.
Golang handle kill signal
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)
}()
@GusGA
Copy link

GusGA commented Jun 2, 2024

you should listen syscall.SIGKILL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment