Created
September 27, 2018 07:47
-
-
Save islishude/7ea25691cc2f5e1cf9b850dbf3115bb7 to your computer and use it in GitHub Desktop.
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" | |
"syscall" | |
) | |
func main() { | |
fmt.Println("Run start and PID is", os.Getpid()) | |
stop := make(chan bool) | |
go func() { | |
c := make(chan os.Signal, 1) | |
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) | |
switch <-c { | |
case syscall.SIGINT: | |
fmt.Println("SIGINT") | |
stop <- true | |
case syscall.SIGTERM: | |
fmt.Println("SIGTERM") | |
stop <- true | |
default: | |
stop <- false | |
} | |
}() | |
<-stop | |
fmt.Println("STOP") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment