-
-
Save gadiener/70ca6712d38c47a1f1472d8a6719c667 to your computer and use it in GitHub Desktop.
Revisions
-
reiki4040 created this gist
Oct 2, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ package main import ( "fmt" "os" "os/signal" "syscall" ) func main() { signal_chan := make(chan os.Signal, 1) signal.Notify(signal_chan, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) exit_chan := make(chan int) go func() { for { s := <-signal_chan switch s { // kill -SIGHUP XXXX case syscall.SIGHUP: fmt.Println("hungup") // kill -SIGINT XXXX or Ctrl+c case syscall.SIGINT: fmt.Println("Warikomi") // kill -SIGTERM XXXX case syscall.SIGTERM: fmt.Println("force stop") exit_chan <- 0 // kill -SIGQUIT XXXX case syscall.SIGQUIT: fmt.Println("stop and core dump") exit_chan <- 0 default: fmt.Println("Unknown signal.") exit_chan <- 1 } } }() code := <-exit_chan os.Exit(code) }