Skip to content

Instantly share code, notes, and snippets.

@nikos-glikis
Created March 26, 2019 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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)
}()
@PouryDev
Copy link

Bro this is for termination and interrupt signals not task kill signal:))

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