Forked from
GitLab.org / gitlab-runner
10719 commits behind the upstream repository.
-
Kamil Trzciński authoredKamil Trzciński authored
process_group_unix.go 481 B
// +build darwin dragonfly freebsd linux netbsd openbsd
package helpers
import (
"os/exec"
"syscall"
)
func SetProcessGroup(cmd *exec.Cmd) {
// Create process group
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
}
func KillProcessGroup(cmd *exec.Cmd) {
if cmd == nil {
return
}
process := cmd.Process
if process != nil {
if process.Pid > 0 {
syscall.Kill(-process.Pid, syscall.SIGKILL)
} else {
// doing normal kill
process.Kill()
}
}
}