Go 超时中断然后终止
示例
c := exec.Command(name, arg...)
b := &bytes.Buffer{}
c.Stdout = b
c.Stdin = stdin
if err := c.Start(); err != nil {
return nil, err
}
timedOut := false
intTimer := time.AfterFunc(timeout, func() {
log.Printf("Process taking too long. Interrupting: %s %s", name, strings.Join(arg, " "))
c.Process.Signal(os.Interrupt)
timedOut = true
})
killTimer := time.AfterFunc(timeout*2, func() {
log.Printf("Process taking too long. Killing: %s %s", name, strings.Join(arg, " "))
c.Process.Signal(os.Kill)
timedOut = true
})
err := c.Wait()
intTimer.Stop()
killTimer.Stop()
if timedOut {
log.Print("the process timed out\n")
}
热门推荐
8 小托班祝福语简短
10 女孩唱生日祝福语简短
11 教育集团发展祝福语简短
12 花茶礼盒生日祝福语简短
13 客户十一祝福语大全 简短
14 感谢室友毕业祝福语简短
15 恩师贺卡文案祝福语简短
16 简短有内涵新年祝福语
17 对当兵的祝福语简短
18 幼儿篮球祝福语大全简短