imsnif/bandwhich · error
failed to execute process
Error message
failed to execute process
What it means
bandwhich shells out to the system `lsof` utility to map sockets to processes. In `run`, if `Command::new("lsof").args(args).output()` fails (most commonly lsof is not installed/not on PATH), it panics with 'failed to execute process'.
Solutions
- Install lsof: Debian/Ubuntu `sudo apt install lsof`, RHEL/Fedora `sudo dnf install lsof`, Arch `sudo pacman -S lsof`
- Verify `which lsof` finds it and PATH includes its directory
- If the binary exists, check execute permissions (`chmod +x $(which lsof)`)
- In minimal containers, add lsof to the image, or run on a platform where bandwhich uses an alternative backend
Example fix
// before sudo bandwhich # panicked at 'failed to execute process' (no lsof) // after sudo apt install lsof && sudo bandwhich
Defensive patterns
Strategy: fallback
Validate before calling
// shell: verify lsof exists before launching
command -v lsof >/dev/null 2>&1 || { echo "lsof is required: install it first"; exit 1; } Try / catch
match Command::new("lsof").args(args).output() {
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
Err(e) => { eprintln!("lsof spawn failed: {e}; install lsof"); String::new() }
} Prevention
- Install lsof on all hosts/containers that run bandwhich (it is a runtime dependency on Linux)
- Keep /usr/bin or /usr/sbin in PATH so lsof is discoverable
- In Docker images, add lsof to the base image packages
- Periodically verify `which lsof` after image slimming or distro upgrades
When it happens
Trigger: `run()` called by `get_connections()` when `lsof` is missing from PATH, lacks execute permission, or spawn fails due to resource limits (fork failures).
Common situations: Linux systems without the lsof package installed (minimal Docker images, slim distros), PATH missing /usr/sbin or custom bin dirs, or corrupted/blocked binaries.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Failed to write to stdout
- Failed to get stdout: if you are trying to pipe 'bandwhich'…
- Failed to find any network interface to listen on.
- {err_msg}
- failed to set SIGINT handler
AI-assisted analysis of imsnif/bandwhich@1899870cea (2026-09-08).
Data as JSON: /api/errors/1fa4d4d0e54ce69c.
Report an issue: GitHub.
Appendix: source
Thrown at src/os/lsof_utils.rs:155
Some(LocalSocket { ip, port, protocol })
}
}
pub fn get_connections() -> RawConnections {
let content = run(["-n", "-P", "-i4", "-i6", "+c", "0"]);
RawConnections::new(content)
}
fn run<I, S>(args: I) -> String
where
I: IntoIterator<Item = S>,
S: AsRef<OsStr>,
{
let output = Command::new("lsof")
.args(args)
.output()
.expect("failed to execute process");
String::from_utf8_lossy(&output.stdout).into_owned()
}
pub struct RawConnections {
content: Vec<RawConnection>,
}
impl RawConnections {
pub fn new(content: String) -> RawConnections {
let lines: Vec<RawConnection> = content.lines().flat_map(RawConnection::new).collect();
RawConnections { content: lines }
}
}
impl Iterator for RawConnections {
type Item = RawConnection;View on GitHub (pinned to 1899870cea)