fix(exec): terminate process tree on timeout
This commit is contained in:
1 parent
ba47892bcf
commit
acac1972e6
4 files changed
+148
-2
No files matched your search
@@ -0,0 +1,27 @@
|
||||
//go:build windows
|
||||
|
||||
package tools
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func prepareCommandForTermination(cmd *exec.Cmd) {
|
||||
// no-op on Windows
|
||||
}
|
||||
|
||||
func terminateProcessTree(cmd *exec.Cmd) error {
|
||||
if cmd == nil || cmd.Process == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
pid := cmd.Process.Pid
|
||||
if pid <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
_ = exec.Command("taskkill", "/T", "/F", "/PID", strconv.Itoa(pid)).Run()
|
||||
_ = cmd.Process.Kill()
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user