返回 last30days-skill
wait_noreap_linux.go
根目录 / mcp / internal / engine / wait_noreap_linux.go
1 //go:build linux
2
3 package engine
4
5 import (
6 "syscall"
7 "unsafe"
8 )
9
10 const linuxWaitPID = 1 // P_PID from <sys/wait.h>
11
12 // waitChildNoReap blocks until child pid exits without reaping it, keeping
13 // the zombie pinned in the kernel process table so its PID/PGID cannot be
14 // recycled before group signaling completes.
15 func waitChildNoReap(pid int) error {
16 // Linux struct siginfo is 128 bytes across architectures; [16]uint64
17 // guarantees 8-byte alignment.
18 var siginfo [16]uint64
19 for {
20 _, _, errno := syscall.Syscall6(
21 syscall.SYS_WAITID,
22 uintptr(linuxWaitPID),
23 uintptr(pid),
24 uintptr(unsafe.Pointer(&siginfo[0])),
25 uintptr(syscall.WEXITED|syscall.WNOWAIT),
26 0,
27 0,
28 )
29 if errno == 0 {
30 return nil
31 }
32 if errno == syscall.EINTR {
33 continue
34 }
35 switch errno {
36 case syscall.ENOSYS, syscall.EPERM, syscall.EACCES, syscall.EINVAL:
37 return errWaitNoReapUnsupported
38 }
39 return errno
40 }
41 }
42
42 lines GO