Last active
November 10, 2021 11:30
-
-
Save JensRantil/5073646 to your computer and use it in GitHub Desktop.
Simple test to test SIGINT signal handling of 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
| #!/bin/bash | |
| # Executed on MacOSX | |
| go build signal.go | |
| ./signal & | |
| kill -INT $! | |
| # Prints the "interrupt" and quits after 5 seconds, which is to be expected. |
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" | |
| "time" | |
| ) | |
| func main() { | |
| c := make(chan os.Signal) | |
| signal.Notify(c) | |
| for sig := range(c) { | |
| fmt.Println(sig.String()) | |
| time.Sleep(5 * time.Second) | |
| return | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment