MCPcopy Index your code
hub / github.com/codehamr/codehamr / setProcessGroup

Function setProcessGroup

internal/tools/bash_unix.go:14–23  ·  view source on GitHub ↗

setProcessGroup gives the shell its own process group and a Cancel that SIGKILLs the whole group. Without it, backgrounded children (`cmd &`) outlive the shell on cancel or timeout, the leak we prevent. Unix-only: Setpgid and negative-PID Kill aren't portable (Windows has its own build).

(cmd *exec.Cmd)

Source from the content-addressed store, hash-verified

12// the shell on cancel or timeout, the leak we prevent. Unix-only: Setpgid and
13// negative-PID Kill aren't portable (Windows has its own build).
14func setProcessGroup(cmd *exec.Cmd) {
15 cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
16 cmd.Cancel = func() error {
17 if cmd.Process == nil {
18 return nil
19 }
20 // Negative pid targets the whole group (shell is the leader).
21 return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
22 }
23}

Callers 1

BashFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected