MCPcopy Create free account
hub / github.com/PasarGuard/node / isProcessZombie

Function isProcessZombie

backend/xray/process_windows.go:187–233  ·  view source on GitHub ↗

isProcessZombie checks if a process is a zombie on Windows On Windows, we check if the process exists but parent doesn't exist or is invalid

(pid int)

Source from the content-addressed store, hash-verified

185// isProcessZombie checks if a process is a zombie on Windows
186// On Windows, we check if the process exists but parent doesn't exist or is invalid
187func isProcessZombie(pid int) bool {
188 // Get process info to check parent
189 cmd := exec.Command("wmic", "process", "where", fmt.Sprintf("ProcessId=%d", pid), "get", "ParentProcessId", "/format:list")
190 output, err := cmd.Output()
191 if err != nil {
192 return false
193 }
194
195 lines := strings.Split(string(output), "\n")
196 var ppidStr string
197 for _, line := range lines {
198 line = strings.TrimSpace(line)
199 if strings.HasPrefix(line, "ParentProcessId=") {
200 ppidStr = strings.TrimPrefix(line, "ParentProcessId=")
201 ppidStr = strings.TrimSpace(ppidStr)
202 break
203 }
204 }
205
206 if ppidStr == "" {
207 return false
208 }
209
210 ppid, err := strconv.Atoi(ppidStr)
211 if err != nil {
212 return false
213 }
214
215 // Check if parent process exists
216 // If parent doesn't exist but this process does, it might be orphaned
217 // However, on Windows, orphaned processes are typically adopted by init (PID 0 or 4)
218 // So we check if parent is system process and this process still exists
219 if ppid <= 4 {
220 // Parent is system process, check if this process is still running
221 // but might be in a bad state
222 return isProcessRunning(pid)
223 }
224
225 // Check if parent process exists
226 parentExists := isProcessRunning(ppid)
227 if !parentExists && isProcessRunning(pid) {
228 // Process exists but parent doesn't - likely orphaned/zombie
229 return true
230 }
231
232 return false
233}

Callers 1

findXrayProcessesFunction · 0.70

Calls 1

isProcessRunningFunction · 0.70

Tested by

no test coverage detected