diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-05-25 23:11:16 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-05-25 23:11:16 +0100 |
| commit | d5813fb189c3d9750d61bb1a5f2aa99fcd804ac6 (patch) | |
| tree | 7cc1ecb79515ce36f3bb9ea58724d84269417a2d | |
| parent | a9f7a2048047fa2e0b69b052d4d91d122f870e3d (diff) | |
propper termination otherwise endless loop
| -rw-r--r-- | gstat/main.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/gstat/main.go b/gstat/main.go index 312e066..ab345c1 100644 --- a/gstat/main.go +++ b/gstat/main.go @@ -4,6 +4,9 @@ import ( "fmt" "github.com/buetow/gstat/diskstats" "github.com/buetow/gstat/process" + "os" + "os/signal" + "syscall" "time" ) @@ -84,11 +87,19 @@ func main() { go receiveD(dRxChan) go receiveP(pRxChan) - for counter := 0; counter < 5; counter++ { + termChan := make(chan os.Signal, 1) + signal.Notify(termChan, os.Interrupt) + signal.Notify(termChan, syscall.SIGTERM) + + go func() { + <-termChan + timerChan <- false + fmt.Println("Good bye") + os.Exit(1) + }() + + for { timerChan <- true time.Sleep(time.Second * 2) } - timerChan <- false - - fmt.Println("Good bye") } |
