picoclaw/pkg/tools/shell_process_unix.go
dj-oyu d8b0f26b79 refactor: replace moderate-diff Go files with upstream, add fork extensions
Replace ~30 more Go source files with upstream versions and re-add
fork-only functionality via appended code or _ext.go files.

Key files aligned: providers/types.go, state/state.go, tools/base.go,
tools/registry.go, channels/*, config/defaults.go, providers/*.

Conflict metrics: 105 → 34 files, 646 → 315 markers (-51%)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 09:48:58 +09:00

32 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
}