返回 DeepSeek-Reasonix
pidprobe_windows_test.go
根目录 / internal / boot / pidprobe_windows_test.go
1 //go:build windows
2
3 package boot
4
5 import (
6 "errors"
7
8 "golang.org/x/sys/windows"
9 )
10
11 // pidAlive reports whether pid still exists. ERROR_ACCESS_DENIED means the
12 // process exists but we lack query rights, so it counts as alive; every
13 // other OpenProcess failure (including ERROR_INVALID_PARAMETER for a dead
14 // pid) means gone.
15 func pidAlive(pid int) bool {
16 if pid <= 0 {
17 return false
18 }
19 h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
20 if err != nil {
21 return errors.Is(err, windows.ERROR_ACCESS_DENIED)
22 }
23 defer func() { _ = windows.CloseHandle(h) }()
24 var code uint32
25 if err := windows.GetExitCodeProcess(h, &code); err != nil {
26 return true
27 }
28 const stillActive = 259
29 return code == stillActive
30 }
31
31 lines GO