{"record":{"id":"907d7abe3330aeea","repo":"affaan-m/ECC","slug":"taskkill-exited-with-status-status","errorCode":null,"errorMessage":"taskkill exited with status {status}","messagePattern":"taskkill exited with status (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"ecc2/src/session/manager.rs","lineNumber":3618,"sourceCode":"#[cfg(unix)]\nfn kill_process(pid: u32) -> Result<()> {\n    send_signal(pid, libc::SIGTERM)?;\n    std::thread::sleep(std::time::Duration::from_millis(1200));\n    send_signal(pid, libc::SIGKILL)?;\n    Ok(())\n}\n\n#[cfg(windows)]\nfn kill_process(pid: u32) -> Result<()> {\n    let status = std::process::Command::new(\"taskkill\")\n        .args([\"/PID\", &pid.to_string(), \"/T\", \"/F\"])\n        .status()\n        .with_context(|| format!(\"Failed to invoke taskkill for process {pid}\"))?;\n\n    if status.success() {\n        Ok(())\n    } else {\n        Err(anyhow::anyhow!(\"taskkill exited with status {status}\"))\n    }\n}\n\n#[cfg(unix)]\nfn send_signal(pid: u32, signal: i32) -> Result<()> {\n    let outcome = unsafe { libc::kill(pid as i32, signal) };\n    if outcome == 0 {\n        return Ok(());\n    }\n\n    let error = std::io::Error::last_os_error();\n    if error.raw_os_error() == Some(libc::ESRCH) {\n        return Ok(());\n    }\n\n    Err(error).with_context(|| format!(\"Failed to kill process {pid}\"))\n}\n","sourceCodeStart":3600,"sourceCodeEnd":3636,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/ecc2/src/session/manager.rs#L3600-L3636","documentation":"On Windows, the kill_process function invokes taskkill /PID <pid> /T /F to terminate a process tree. If taskkill exits with a non-zero status code, the function returns an error. This typically means the target process does not exist, access is denied, or taskkill itself failed.","triggerScenarios":"Calling kill_process(pid) on Windows where taskkill returns a non-zero exit code — the process may have already exited, the PID may be invalid, or the user lacks permissions.","commonSituations":"Process already exited before the kill call. PID belongs to a process owned by a different user or with higher privileges. taskkill.exe is not available or restricted by group policy. Antivirus blocking taskkill.","solutions":["Check if the process is still running before attempting to kill it (track exit independently)","Run the ECC process with sufficient privileges to terminate the target process","Treat ESRCH-equivalent (process already gone) as success rather than error","Use the /F flag (already present) and ensure /T is used to kill the entire process tree"],"exampleFix":"// before\nkill_process(pid)?;\n\n// after\nmatch kill_process(pid) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"taskkill exited\") => {\n        tracing::warn!(\"process {pid} may have already exited: {e}\");\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match kill_process(pid) {\n    Ok(()) => Ok(()),\n    Err(e) if e.to_string().contains(\"taskkill exited\") => {\n        tracing::warn!(\"taskkill failed for pid {pid}, process may have already exited: {e}\");\n        Ok(())\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Check if the process is still alive before attempting to kill it on Windows","Run ECC with sufficient privileges to terminate spawned processes","Treat 'process already gone' as success to avoid cascading errors in cleanup paths"],"tags":["process","kill","windows","taskkill"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}