Skip to content

Error codes & fixes: Exit codes

10 Error codes & fixes commands: Exit codes. Click a command to see what each part does.

Index
10 items
Click a command to see what each part does.

Exit codes10

  • echo $?$?What did the last command return?

    What it means

    Every command returns a number 0-255. 0 means success. CI jobs and && use it.

    Usual causes & fixes

    • Check it right after the command; the next command overwrites it.
    • In scripts use set -e to stop on the first failure, set -o pipefail to catch failures inside pipes.

    Diagnose: what each part of the command does

    1. echoprint
    2. $?exit status of the last command: 0 = success, anything else = failure
  • bash -x <script>.sh1General error: trace the script

    What it means

    Catch-all for general errors: the program failed and chose 1.

    Usual causes & fixes

    • Read the last lines of stderr: the real message is usually there.
    • A command inside the script failed: -x shows which one.

    Diagnose: what each part of the command does

    1. bashrun the script with bash
    2. -xprint every command (with expanded variables) before running it
  • <command> --help2Misuse / wrong arguments

    What it means

    Bash builtins return 2 for incorrect usage (invalid option, missing argument); many tools follow this.

    Usual causes & fixes

    • Typo in a flag or a missing required argument.
    • Shell syntax error in a script.

    Diagnose: what each part of the command does

    1. --helpshow valid options and arguments
  • ls -l <file>; file <file>126Found but cannot execute

    What it means

    The command exists but is not executable.

    Usual causes & fixes

    • Missing execute bit: chmod +x <file>.
    • Windows line endings in a script: sed -i 's/\r$//' <file> (or dos2unix).
    • Filesystem mounted noexec: findmnt -o TARGET,OPTIONS -T <file>.

    Diagnose: what each part of the command does

    1. ls -l <file>check the x permission bit
    2. file <file>check the type: script with CRLF line terminators, wrong binary format…
  • command -v <command> || echo "not found; PATH=$PATH"127Command not found

    What it means

    The shell could not find the program in any PATH folder.

    Usual causes & fixes

    • Not installed (install it with apt/dnf/apk).
    • Installed in a folder not on PATH (e.g. ~/.local/bin): export PATH="$HOME/.local/bin:$PATH".
    • Typo, or a container image that does not include the tool (distroless, alpine without bash).

    Diagnose: what each part of the command does

    1. command -v <command>print where the command is, or nothing if it is not found
    2. ||if that failed…
    3. echo "…PATH=$PATH"…show the folders the shell searches
  • kill -l $(( <exit-code> - 128 ))128+NKilled by a signal: which one?

    What it means

    When a process dies from signal N, the shell reports 128+N. E.g. 137 → 9 (KILL), 143 → 15 (TERM), 130 → 2 (INT).

    Usual causes & fixes

    • Run it with the code you got, e.g. kill -l $(( 137 - 128 )) prints KILL.

    Diagnose: what each part of the command does

    1. kill -l <number>print the signal name for a number
    2. $(( … ))shell arithmetic
    3. <exit-code> - 128exit codes above 128 mean "terminated by signal N"
  • kill -l 2130Stopped with Ctrl+C

    What it means

    128 + 2 (SIGINT): someone (or something) pressed Ctrl+C / sent an interrupt.

    Usual causes & fixes

    • Expected if you stopped it. In CI it usually means the job was cancelled.

    Diagnose: what each part of the command does

    1. kill -l 2signal 2 = INT, what Ctrl+C sends
  • dmesg -T | grep -i -E "out of memory|killed process"137Killed (SIGKILL): usually out of memory

    What it means

    128 + 9 (SIGKILL): the process was force-killed. In containers this is almost always the memory limit (OOMKilled).

    Usual causes & fixes

    • Docker: docker inspect --format '{{.State.OOMKilled}}' <container>; raise -m or fix the leak.
    • Kubernetes: kubectl describe pod <pod> → Last State: Terminated, Reason: OOMKilled; raise resources.limits.memory.
    • A human or script ran kill -9, or a stop timed out and was escalated.

    Diagnose: what each part of the command does

    1. dmesg -Tkernel messages with readable timestamps
    2. grep -i -E "out of memory|killed process"the OOM killer lines
  • dmesg -T | grep -i segfault139Segmentation fault (SIGSEGV)

    What it means

    128 + 11 (SIGSEGV): the program accessed invalid memory and crashed.

    Usual causes & fixes

    • Bug in a native binary or library; version mismatch between binary and libs (e.g. glibc vs musl/alpine).
    • Wrong CPU architecture image under emulation.

    Diagnose: what each part of the command does

    1. dmesg -Tkernel log
    2. grep -i segfaultlines about the crash (which binary, which library)
  • docker inspect --format '{{.State.ExitCode}} {{.State.FinishedAt}}' <container>143Terminated (SIGTERM): asked to stop

    What it means

    128 + 15 (SIGTERM): a graceful stop request: docker stop, a Kubernetes rollout/scale-down, systemctl stop.

    Usual causes & fixes

    • Normal during deploys and restarts.
    • If unexpected: check who stopped it (events, kubectl get events, systemd journal).
    • App should handle SIGTERM and exit cleanly within the grace period (terminationGracePeriodSeconds, default 30s).

    Diagnose: what each part of the command does

    1. docker inspectcontainer details
    2. --format '…'print just the exit code and when it stopped

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…