Configures spawned shell commands as process-group leaders and kills entire groups, ensuring kill_shell terminates descendants like npm/node. Reuse for Unix subprocess cleanup.
// Source: https://github.com/fastclaw-ai/fastclaw | License: Apache-2.0 | Copyright 2026 ThinkAny, LLC
// Provided via justclaw.it.com; keep this notice with the code.
//go:build unix
package tools
import (
"errors"
"os/exec"
"syscall"
)
// setProcessGroup configures the command to spawn into a NEW process
// group (Setpgid=true with Pgid=0 makes the child the group leader).
// Must be set before cmd.Start. Together with killProcessGroup this
// guarantees `kill_shell` reaches every descendant the command spawned
// — without it, killing `sh -c "npm run dev"` leaves the node process
// orphaned and still bound to the dev server's port.
func setProcessGroup(cmd *exec.Cmd) {
if cmd.SysProcAttr == nil {
cmd.SysProcAttr = &syscall.SysProcAttr{}
}
cmd.SysProcAttr.Setpgid = true
}
/
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key