You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool/nsys/cmdn/cmd_linux.go

22 lines
723 B
Go

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{Setpgid: true}
}