Files
ThothII/tools/tht/internal/compose/process_unix.go
T

37 lines
737 B
Go

//go:build !windows
package compose
import (
"os/exec"
"syscall"
"time"
)
const gracefulTerminationBound = 500 * time.Millisecond
const finalTerminationBound = 2 * time.Second
func configureProcess(command *exec.Cmd) {
command.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
}
func terminateProcess(command *exec.Cmd, done <-chan error) error {
if command.Process == nil {
return nil
}
_ = syscall.Kill(-command.Process.Pid, syscall.SIGINT)
select {
case <-done:
return nil
case <-time.After(gracefulTerminationBound):
}
_ = syscall.Kill(-command.Process.Pid, syscall.SIGKILL)
_ = command.Process.Kill()
select {
case <-done:
return nil
case <-time.After(finalTerminationBound):
return ErrProcessReap
}
}