Skip to content

Instantly share code, notes, and snippets.

@islishude
Created September 27, 2018 07:47
Show Gist options
  • Save islishude/7ea25691cc2f5e1cf9b850dbf3115bb7 to your computer and use it in GitHub Desktop.
Save islishude/7ea25691cc2f5e1cf9b850dbf3115bb7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
fmt.Println("Run start and PID is", os.Getpid())
stop := make(chan bool)
go func() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
switch <-c {
case syscall.SIGINT:
fmt.Println("SIGINT")
stop <- true
case syscall.SIGTERM:
fmt.Println("SIGTERM")
stop <- true
default:
stop <- false
}
}()
<-stop
fmt.Println("STOP")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment