Skip to content

Instantly share code, notes, and snippets.

@wofeiwo
Created September 1, 2012 18:37
Show Gist options
  • Save wofeiwo/3582748 to your computer and use it in GitHub Desktop.
Save wofeiwo/3582748 to your computer and use it in GitHub Desktop.
Signal handle in golang
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