Skip to content

Instantly share code, notes, and snippets.

@montanaflynn
Created October 8, 2015 20:12
Show Gist options
  • Save montanaflynn/118f51866f1c0dec61a8 to your computer and use it in GitHub Desktop.
Save montanaflynn/118f51866f1c0dec61a8 to your computer and use it in GitHub Desktop.
Listen for SIGINFO to report progress
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
var i int
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINFO)
go func() {
for {
<-sigs
fmt.Printf("Processed up to: %d\n", i)
}
}()
// simulate doing lots of hard work for 60 seconds
go func() {
for {
i++
time.Sleep(500 * time.Millisecond)
}
}()
time.Sleep(60 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment