Created
February 3, 2016 01:16
-
-
Save 178inaba/b54f9dbf408c0d1590ad to your computer and use it in GitHub Desktop.
receive signal of golang
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" | |
| import "os" | |
| import "os/signal" | |
| import "syscall" | |
| func main() { | |
| sigs := make(chan os.Signal, 1) | |
| done := make(chan bool, 1) | |
| signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | |
| go func() { | |
| for i := 0; i < 10; i++ { | |
| sig := <-sigs | |
| fmt.Println() | |
| fmt.Println(sig) | |
| } | |
| done <- true | |
| }() | |
| fmt.Println("awaiting signal") | |
| <-done | |
| fmt.Println("exiting") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment