{"record":{"id":"8dd4467172931821","repo":"uutils/coreutils","slug":"error-no-such-process","errorCode":null,"errorMessage":"error-no-such-process","messagePattern":"error-no-such-process","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"info","filePath":"src/uucore/src/lib/features/process/windows.rs","lineNumber":481,"sourceCode":"        Disposition::Probe => match sys::wait_for_one(child.as_handle(), 0)? {\n            sys::WaitOutcome::TimedOut => Ok(()),\n            // The process has exited: the POSIX analog is ESRCH.\n            sys::WaitOutcome::Object(_) => Err(io::ErrorKind::NotFound.into()),\n        },\n        Disposition::Ignore => Ok(()),\n        Disposition::Interrupt | Disposition::Terminate => {\n            terminate_with_signal(child.as_handle(), signal)\n        }\n    }\n}\n\nconst PROBE_ACCESS: u32 = PROCESS_SYNCHRONIZE;\n// SYNCHRONIZE tells \"already exited\" apart from a real denial after a failed\n// TerminateProcess (both report ERROR_ACCESS_DENIED).\nconst TERMINATE_ACCESS: u32 = PROCESS_TERMINATE | PROCESS_SYNCHRONIZE;\n\nfn no_such_process() -> io::Error {\n    io::Error::new(io::ErrorKind::NotFound, translate!(\"error-no-such-process\"))\n}\n\n/// A process handle becomes signaled when the process exits.\nfn has_exited(handle: BorrowedHandle) -> io::Result<bool> {\n    Ok(matches!(\n        sys::wait_for_one(handle, 0)?,\n        sys::WaitOutcome::Object(_)\n    ))\n}\n\n/// Request `SeDebugPrivilege` once per process; with it, opening a process\n/// bypasses the target's security descriptor.\n///\n/// Silent and best-effort: only an elevated administrator's token holds the\n/// privilege, and tokens without it are left untouched.\npub fn enable_debug_privilege() {\n    static REQUESTED: OnceLock<()> = OnceLock::new();\n    REQUESTED.get_or_init(|| {","sourceCodeStart":463,"sourceCodeEnd":499,"githubUrl":"https://github.com/uutils/coreutils/blob/325183372aaf86d8ae6feaf4f9548f74fe815102/src/uucore/src/lib/features/process/windows.rs#L463-L499","documentation":"On Windows, `no_such_process` constructs an `io::Error` with `ErrorKind::NotFound` carrying the localized \"error-no-such-process\" message. `probe_pid` opens the process with PROCESS_SYNCHRONIZE only; if the open fails with ERROR_ACCESS_DENIED (a real denial after a failed TerminateProcess) versus the process already having exited, this error signals the process does not exist.","triggerScenarios":"Calling `probe_pid` (and by extension kill/terminate paths) with a PID whose process has already exited, or a PID that never existed on the system.","commonSituations":"Killing a process that already terminated (race), stale PIDs from a previous session, PID reuse assumptions in scripts.","solutions":["Check the process still exists before signaling, and treat NotFound as success for kill semantics","Refresh the PID from the source that spawned it","Ignore this error in fire-and-forget termination logic"],"exampleFix":"// before\nkill(pid).expect(\"kill failed\");\n// after\nif let Err(e) = kill(pid) {\n    if e.kind() != io::ErrorKind::NotFound {\n        return Err(e);\n    } // already exited: fine\n}","handlingStrategy":"try-catch","validationCode":"// Windows: probe first\nfn pid_exists(pid: u32) -> bool {\n    // probe_pid returns Err(NotFound) if the process has exited\n    probe::probe_pid(pid).is_ok()\n}","typeGuard":"fn is_no_such_process(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::NotFound\n        && e.to_string().contains(\"no such process\")\n}","tryCatchPattern":"if let Err(e) = kill(pid) {\n    if !is_no_such_process(&e) { return Err(e); }\n    // already exited: treat as success\n}","preventionTips":["Treat NotFound as success in idempotent kill logic","Avoid caching PIDs across sessions","Re-read PID files right before signaling"],"tags":["windows","process","kill"],"backgroundTag":"no-such-process","analyzedSha":"325183372aaf86d8ae6feaf4f9548f74fe815102","analyzedAt":"2026-08-31T11:11:36.175Z","contentChangedAt":"2026-08-31T11:11:36.175Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}