Created
September 1, 2012 18:37
-
-
Save wofeiwo/3582748 to your computer and use it in GitHub Desktop.
Signal handle in golang
This file contains 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" | |
) | |
func main() { | |
// 处理一下Ctrl+c | |
c := make(chan os.Signal, 1) | |
signal.Notify(c, os.Interrupt) | |
go func() { | |
<-c | |
fmt.Printf("Error: user interrupt.") | |
os.Exit(-1) | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment