45 lines
880 B
Go
45 lines
880 B
Go
//go:build linux
|
|
|
|
package utility
|
|
|
|
import (
|
|
"errors"
|
|
"os/exec"
|
|
"syscall"
|
|
)
|
|
|
|
func setACPCommandProcAttr(cmd *exec.Cmd) {
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
Setpgid: true,
|
|
Pdeathsig: syscall.SIGTERM,
|
|
}
|
|
}
|
|
|
|
type acpCommandLifecycleHandle struct{}
|
|
|
|
func installACPCommandLifecycle(_ *exec.Cmd) (acpCommandLifecycleHandle, error) {
|
|
return acpCommandLifecycleHandle{}, nil
|
|
}
|
|
|
|
func releaseACPCommandLifecycle(_ acpCommandLifecycleHandle) {}
|
|
|
|
func terminateACPProcessGroup(pid int) error {
|
|
return syscall.Kill(-pid, syscall.SIGTERM)
|
|
}
|
|
|
|
func killACPProcessGroup(pid int) error {
|
|
return syscall.Kill(-pid, syscall.SIGKILL)
|
|
}
|
|
|
|
func acpProcessGroupAlive(pid int) bool {
|
|
if pid <= 0 {
|
|
return false
|
|
}
|
|
err := syscall.Kill(-pid, 0)
|
|
return err == nil || errors.Is(err, syscall.EPERM)
|
|
}
|
|
|
|
func acpProcessGroupMissing(err error) bool {
|
|
return errors.Is(err, syscall.ESRCH)
|
|
}
|