ClementTsang/bottom · error
Error code unknown
Error message
Error code unknown - {err} What it means
Sibling of the `Error code {err_code}` bail in the Unix `kill_process_given_pid`: when `std::io::Error::last_os_error().raw_os_error()` returns `None` — i.e. the OS did not report a recognizable errno — the library bails with `Error code unknown - {err}` (err will read 'Unknown error occurred.'). This is a rare fallback path meaning `libc::kill` failed but the thread-local errno could not be interpreted.
Solutions
- Retry the kill once and inspect the new error — transient errno clobbering is usually not reproducible
- Check that the PID is valid and the signal value is in range, then retry with a corrected call
- Capture `std::io::Error::last_os_error()` display text for the real cause and report it upstream if it persists
Defensive patterns
Strategy: retry
Try / catch
match kill_process_given_pid(pid, signal) {
Err(e) if e.to_string().contains("Error code unknown") => {
// retry once; errno was unreadable
if let Err(e2) = kill_process_given_pid(pid, signal) {
eprintln!("kill retry failed: {e2}");
}
}
other => { let _ = other; }
} Prevention
- Retry once on unknown-errno failures before giving up
- Keep errno-reading code immediately after the failing libc call
- Validate pid and signal before calling so only genuine OS failures reach this path
- Log the full std::io::Error display for diagnostics when it recurs
When it happens
Trigger: `libc::kill` returned non-zero but `last_os_error()` produced an error without a raw errno (e.g. errno was clobbered by an intervening call, or the error carried no OS code).
Common situations: Unusual libc/platform conditions or interleaving code between the failed `kill` and the errno read on exotic libc implementations; very rare in practice on standard Linux/macOS.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Error code
- statvfs failed to get the disk usage for disk
- failed to get process for pid
- process may have already been terminated.
AI-assisted analysis of ClementTsang/bottom@b77d317502 (2026-09-07).
Data as JSON: /api/errors/b899dccca3cb645f.
Report an issue: GitHub.
Appendix: source
Thrown at src/utils/process_killer.rs:83
// code not 0).
let output = unsafe { libc::kill(pid, signal as i32) };
if output != 0 {
// We had an error...
let err_code = std::io::Error::last_os_error().raw_os_error();
let err = match err_code {
Some(libc::ESRCH) => "the target process did not exist.",
Some(libc::EPERM) => {
"the calling process does not have the permissions to terminate the target process(es)."
}
Some(libc::EINVAL) => "an invalid signal was specified.",
_ => "Unknown error occurred.",
};
if let Some(err_code) = err_code {
bail!(format!("Error code {err_code} - {err}"))
} else {
bail!(format!("Error code unknown - {err}"))
};
}
Ok(())
}
View on GitHub (pinned to b77d317502)