func main() { tw, err := taskstats.NewWatcher() if err != nil { log.Fatal(err) } exec := make(chan int) exit := make(chan int) go func() { for { ev0, err := tw.Event() if err != nil { log.Fatal(err) } switch ev := ev0.(type) { case *taskstats.ExecEvent: exec <- ev.Pid case *taskstats.ExitEvent: exit <- ev.Pid } } }() for { select { case pid := <-exec: manager.AddTask(pid) case pid := <-exit: manager.RmTask(pid) } } }
func main() { mon, err := taskstats.NewWatcher() if err != nil { log.Fatal(err) } for { ev0, err := mon.Event() if err != nil { log.Fatal(err) } switch ev := ev0.(type) { case *taskstats.ExecEvent: log.Println("exec:", ev.Pid) case *taskstats.ExitEvent: log.Println("exit:", ev.Pid) } } }