{"record":{"id":"65518bdf7c9ce73a","repo":"FuelLabs/sway","slug":"failed-to-execute-ps-command","errorCode":null,"errorMessage":"Failed to execute ps command","messagePattern":"Failed to execute ps command","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"forc-util/src/fs_locking.rs","lineNumber":50,"sourceCode":"    }\n\n    /// Create a new PidFileLocking instance that is shared between the LSP and any other process\n    /// that may want to update the file and needs to wait for the LSP to finish (like forc-fmt)\n    pub fn lsp<X: AsRef<Path>>(filename: X) -> PidFileLocking {\n        Self::new(filename, \".lsp-locks\", \"lock\")\n    }\n\n    /// Checks if the given pid is active\n    #[cfg(not(target_os = \"windows\"))]\n    fn is_pid_active(pid: usize) -> bool {\n        // Not using sysinfo here because it has compatibility issues with fuel.nix\n        // https://github.com/FuelLabs/fuel.nix/issues/64\n        use std::process::Command;\n        let output = Command::new(\"ps\")\n            .arg(\"-p\")\n            .arg(pid.to_string())\n            .output()\n            .expect(\"Failed to execute ps command\");\n\n        let output_str = String::from_utf8_lossy(&output.stdout);\n        output_str.contains(&format!(\"{pid} \"))\n    }\n\n    #[cfg(target_os = \"windows\")]\n    fn is_pid_active(pid: usize) -> bool {\n        // Not using sysinfo here because it has compatibility issues with fuel.nix\n        // https://github.com/FuelLabs/fuel.nix/issues/64\n        use std::process::Command;\n        let output = Command::new(\"tasklist\")\n            .arg(\"/FI\")\n            .arg(format!(\"PID eq {}\", pid))\n            .output()\n            .expect(\"Failed to execute tasklist command\");\n\n        let output_str = String::from_utf8_lossy(&output.stdout);\n        // Check if the output contains the PID, indicating the process is active","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-util/src/fs_locking.rs#L32-L68","documentation":"forc-util's file locking serializes concurrent builds of the same package directory. When it inspects an existing lock file, is_pid_active checks the recorded PID by running `ps -p <pid>` (sysinfo is deliberately avoided due to a fuel.nix conflict, per the comment). This expect panics when the ps process itself cannot be spawned — a missing ps binary or a fork failure — not when the target process is gone.","triggerScenarios":"A lock file exists in the package output directory (left by a previous/crashed build) and forc evaluates its staleness in an environment where /usr/bin/ps is absent: distroless/scratch/minimal containers, seccomp profiles blocking process spawn, or PID/resource exhaustion causing spawn failure.","commonSituations":"Running forc build in slim Docker images without procps installed; CI jobs on hand-rolled minimal images; a killed CI build leaving a lock file that the retry run then tries to validate.","solutions":["Install procps in the image: `apt-get update && apt-get install -y procps` (Debian/Ubuntu) or the equivalent for the base image.","Delete the stale lock file from the package's output directory (out/... .forc-lock) so no PID check is needed.","Avoid sharing the build/output directory across containers that cannot see each other's PIDs."],"exampleFix":"# before\nFROM debian:bookworm-slim   # no ps installed; stale lock -> panic\n# after\nFROM debian:bookworm-slim\nRUN apt-get update && apt-get install -y procps && rm -rf /var/lib/apt/lists/*","handlingStrategy":"validation","validationCode":"# entrypoint guard: ps must be spawnable before builds run\ncommand -v ps >/dev/null 2>&1 || { echo \"install procps (apt-get install -y procps)\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Base build images on debian-slim + procps rather than distroless/scratch for forc workloads.","Clean lock files (out/**/.forc-lock) after a killed build so no PID check is attempted.","Don't share output directories between forc processes in different PID namespaces."],"tags":["rust","forc","forc-util","file-locking","panic","containers","procps","environment"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}