Skip to content

Instantly share code, notes, and snippets.

@physacco
Created March 14, 2013 05:07
Show Gist options
  • Save physacco/5158964 to your computer and use it in GitHub Desktop.
Save physacco/5158964 to your computer and use it in GitHub Desktop.
A demo of signal handling in go.
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
c := make(chan os.Signal)
signal.Notify(c) // receive all signals
select {
case sig := <-c:
switch sig {
case syscall.SIGHUP:
fmt.Println("Recv SIGHUP:", sig)
case syscall.SIGINT:
fmt.Println("Recv SIGINT:", sig)
case syscall.SIGQUIT:
fmt.Println("Recv SIGQUIT:", sig)
case syscall.SIGTERM:
fmt.Println("Recv SIGTERM:", sig)
default:
fmt.Println("Unknown signal:", sig)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment