Created
March 24, 2014 21:56
-
-
Save dtjm/9750070 to your computer and use it in GitHub Desktop.
A program that prints out what signal was caught
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 ( | |
"flag" | |
"io" | |
"log" | |
"os" | |
"os/signal" | |
"syscall" | |
) | |
var name *string = flag.String("name", "default", "Name of process") | |
func main() { | |
flag.Parse() | |
log.SetPrefix(*name + " ") | |
c := make(chan os.Signal) | |
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT, syscall.SIGKILL, syscall.SIGABRT, syscall.SIGPIPE) | |
go io.Copy(os.Stdout, os.Stdin) | |
s := <-c | |
log.Println("Got signal", s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment