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

  1. Install lsof: Debian/Ubuntu `sudo apt install lsof`, RHEL/Fedora `sudo dnf install lsof`, Arch `sudo pacman -S lsof`
  2. Verify `which lsof` finds it and PATH includes its directory
  3. If the binary exists, check execute permissions (`chmod +x $(which lsof)`)
  4. 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

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


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)