mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-10 13:11:31 -10:00
* fix(background): treat POSIX zombie leader as already-exited terminateOwnedProcess always returned leaderAlreadyExited=false, so TerminateCommand surfaced "did not exit after SIGKILL" when ps was unavailable and the leader was already a waitable zombie. Probe the leader the way Windows uses GetExitCodeProcess, then still signal the group so live descendants are not skipped. * fix(background): preserve live-group termination failures --------- Co-authored-by: cairn-intern <[email protected]>
29 lines
940 B
Go
29 lines
940 B
Go
//go:build darwin
|
|
|
|
package background
|
|
|
|
import "golang.org/x/sys/unix"
|
|
|
|
// szomb is sys/proc.h SZOMB: the process has exited and is waiting to be reaped.
|
|
const szomb int8 = 5
|
|
|
|
// leaderWaitableExited reports whether pid has already exited and is waiting
|
|
// to be reaped. This is the POSIX analogue of Windows GetExitCodeProcess
|
|
// returning a value other than STILL_ACTIVE: the leader is a zombie, waitable
|
|
// as exited, without collecting it. A true result does not mean the process
|
|
// group is empty — descendants may still be running.
|
|
//
|
|
// Darwin has no /proc and x/sys/unix does not wrap waitid here, so the probe
|
|
// is kern.proc.pid via sysctl. It does not use ps, which is the #862 failure
|
|
// mode when PATH cannot resolve ps.
|
|
func leaderWaitableExited(pid int) bool {
|
|
if pid <= 1 {
|
|
return false
|
|
}
|
|
kinfo, err := unix.SysctlKinfoProc("kern.proc.pid", pid)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return kinfo.Proc.P_stat == szomb
|
|
}
|