Skip to content

Instantly share code, notes, and snippets.

@slawosz
Created March 31, 2015 21:42
Show Gist options
  • Save slawosz/00fe027fa87559579a96 to your computer and use it in GitHub Desktop.
Save slawosz/00fe027fa87559579a96 to your computer and use it in GitHub Desktop.
Go signals
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
// Set up channel on which to send signal notifications.
// We must use a buffered channel or risk missing the signal
// if we're not ready to receive when the signal is sent.
fmt.Println("Got pid:", os.Getpid())
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGUSR1)
// Block until a signal is received.
s := <-c
fmt.Println("Got signal:", s)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment