Created
May 4, 2018 06:23
-
-
Save wrfly/da3ff6deab97f1e837cdea0d112076c4 to your computer and use it in GitHub Desktop.
golang cat signal
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 ( | |
"log" | |
"os" | |
"os/signal" | |
"syscall" | |
) | |
func main() { | |
log.Printf("Service started, pid: [ %d ]", os.Getpid()) | |
defer log.Println("Service stopped") | |
sigChan := make(chan os.Signal) | |
signal.Ignore() | |
signal.Notify(sigChan) | |
for sig := range sigChan { | |
log.Printf("Got signal [ %s ]\n", sig.String()) | |
if sig == syscall.SIGUSR2 { | |
log.Println("quit") | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment