Skip to content

Instantly share code, notes, and snippets.

@JensRantil
Last active November 10, 2021 11:30
Show Gist options
  • Select an option

  • Save JensRantil/5073646 to your computer and use it in GitHub Desktop.

Select an option

Save JensRantil/5073646 to your computer and use it in GitHub Desktop.
Simple test to test SIGINT signal handling of Go.
#!/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.
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