|
|
@ -35,6 +35,17 @@ func ExecCommand(name string, args []string, timeout ...time.Duration) (out stri
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pid := 0
|
|
|
|
|
|
|
|
if cmd.Process != nil && cmd.Process.Pid != 0 {
|
|
|
|
|
|
|
|
pid = cmd.Process.Pid
|
|
|
|
|
|
|
|
pidMap.Store(pid, pid)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
if pid != 0 {
|
|
|
|
|
|
|
|
pidMap.Delete(pid)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
time.AfterFunc(expire, func() {
|
|
|
|
time.AfterFunc(expire, func() {
|
|
|
|
if cmd.Process != nil && cmd.Process.Pid != 0 {
|
|
|
|
if cmd.Process != nil && cmd.Process.Pid != 0 {
|
|
|
|
errs = append(errs, fmt.Sprintf("execute timeout: %d min.", int(expire.Minutes())))
|
|
|
|
errs = append(errs, fmt.Sprintf("execute timeout: %d min.", int(expire.Minutes())))
|
|
|
@ -57,3 +68,17 @@ func ExecCommand(name string, args []string, timeout ...time.Duration) (out stri
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 当主程序退出时,从pidMap中获取所有的pid,然后kill掉
|
|
|
|
|
|
|
|
func CloseChildProccess() {
|
|
|
|
|
|
|
|
pidMap.Range(func(key, value interface{}) bool {
|
|
|
|
|
|
|
|
if pid, ok := value.(int); ok {
|
|
|
|
|
|
|
|
fmt.Println("kill pid:", pid)
|
|
|
|
|
|
|
|
if proc, err := os.FindProcess(pid); err == nil {
|
|
|
|
|
|
|
|
proc.Kill()
|
|
|
|
|
|
|
|
proc.Release()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|