nikivdev/code · error
taskkill exited with status {}
Error message
taskkill exited with status {} What it means
On Windows, terminate_process uses `taskkill /PID <pid> /F /T`; if the command exits non-zero the library bails with `taskkill exited with status <code>`. It indicates Windows refused the forced termination of the daemon process tree (/T also targets children).
Source
Thrown at src/daemon.rs:699
if status.success() || pgid_kill.map(|s| s.success()).unwrap_or(false) {
return Ok(());
}
bail!(
"kill command exited with status {}",
status.code().unwrap_or(-1)
);
}
#[cfg(windows)]
{
let status = Command::new("taskkill")
.args(["/PID", &pid.to_string(), "/F", "/T"]) // /T kills child processes too
.status()
.context("failed to invoke taskkill")?;
if status.success() {
return Ok(());
}
bail!(
"taskkill exited with status {}",
status.code().unwrap_or(-1)
);
}
}
/// Extract port number from a URL like "http://127.0.0.1:7201/health"
pub fn extract_port_from_url(url: &str) -> Option<u16> {
// Simple extraction: find the port after the last colon before any path
let url = url
.strip_prefix("http://")
.or_else(|| url.strip_prefix("https://"))?;
let host_port = url.split('/').next()?;
let port_str = host_port.rsplit(':').next()?;
port_str.parse().ok()
}
/// Kill any process listening on the given port.View on GitHub (pinned to a747e741ae)
Solutions
- Verify the PID is still the daemon: `tasklist /FI "PID eq <pid>"`; refresh the PID file if stale.
- Run the stop/restart command from an elevated (Administrator) prompt.
- Kill by image name as fallback: `taskkill /IM <daemon.exe> /F`.
- Reboot or use Task Manager to terminate a protected/elevated process manually.
Example fix
// before: stop from non-elevated shell fails PS> f daemon stop // taskkill exited with status 1 // after: elevated shell PS (admin)> f daemon stop
Defensive patterns
Strategy: try-catch
Validate before calling
// PowerShell: verify the PID exists and is the daemon before taskkill
$proc = Get-Process -Id $pid -ErrorAction SilentlyContinue
if ($null -eq $proc) { Write-Output 'already stopped' }
elseif ($proc.ProcessName -ne 'myapp-daemon') { Write-Output 'PID reused by another process; aborting' } Try / catch
match terminate_process(pid) {
Ok(()) => println!("daemon stopped"),
Err(e) if e.to_string().contains("taskkill exited") => {
eprintln!("taskkill failed for pid {pid} — run from an elevated prompt or kill via Task Manager.");
}
Err(e) => return Err(e),
} Prevention
- Start and stop the Windows daemon from the same privilege level (both elevated or both normal).
- Validate PID liveness (tasklist) before taskkill; stale PID files are the top cause.
- On daemon exit, delete the PID file in a Drop/exit handler.
- Fall back to `taskkill /IM <exe> /F` by image name when PID kill fails.
When it happens
Trigger: stop_daemon_with_path, start_daemon_inner restart, or kill_process_on_port invoking terminate_process when the PID is invalid/already exited, the process runs elevated while the CLI does not, or the PID was reused by a protected system process.
Common situations: Daemon started from an Administrator shell but stopped from a normal one; stale PID file after a reboot; antivirus or a protected process rejecting the force kill; PID reuse assigning the old number to a system process.
Related errors
- clipboard not supported on this platform
- symlinks are only supported on unix-like systems
- Supervisor IPC is only supported on unix platforms right now
AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01).
Data as JSON: /api/errors/79915589bb67303b.
Report an issue: GitHub.