Created
March 14, 2013 05:07
-
-
Save physacco/5158964 to your computer and use it in GitHub Desktop.
A demo of signal handling in go.
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 characters
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