package cmdn import ( "os/exec" "syscall" ) // terminateProcess stops the command by sending its process group a SIGTERM signal. // Stop is idempotent. An error should only be returning to the rare case that // Stop is called immediately after the command ends but before Start can // update its internal state. func terminateProcess(pid int) error { // Signal the process group (-pid), not just the process, so that the process // and all its children are signaled. Else, child processes can keep running and // keep the stdout/stderr fd open and cause cmd.Wait to hang. return syscall.Kill(-pid, syscall.SIGTERM) } func setProcessGroupID(cmd *exec.Cmd) { cmd.SysProcAttr = &syscall.SysProcAttr{Setgpid: true} }