Files
picoclaw/pkg/tools/shell_process_unix.go
T
2026-02-18 02:01:29 +08:00

33 lines
559 B
Go

//go:build !windows
package tools
import (
"os/exec"
"syscall"
)
func prepareCommandForTermination(cmd *exec.Cmd) {
if cmd == nil {
return
}
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
func terminateProcessTree(cmd *exec.Cmd) error {
if cmd == nil || cmd.Process == nil {
return nil
}
pid := cmd.Process.Pid
if pid <= 0 {
return nil
}
// Kill the entire process group spawned by the shell command.
_ = syscall.Kill(-pid, syscall.SIGKILL)
// Fallback kill on the shell process itself.
_ = cmd.Process.Kill()
return nil
}