From d5813fb189c3d9750d61bb1a5f2aa99fcd804ac6 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (europa)" Date: Mon, 25 May 2015 23:11:16 +0100 Subject: propper termination otherwise endless loop --- gstat/main.go | 19 +++++++++++++++---- 1 file 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") } -- cgit v1.2.3