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")
}
热门推荐
10 初升高祝福语家长简短
11 生日牌祝福语英语简短
12 特别的端午祝福语简短
13 佛教生日祝福语简短大全
14 上嫂子生日祝福语简短
15 父亲祝福语大全简短语
16 农民朋友发财祝福语简短
17 祝福语诗意文案简短
18 分别祝福语简短情侣短句