bitlvl
EN

Exit code reference

Type a code to find it. Anything above 128 means the process was killed by a signal: subtract 128 to get the signal number.

 
CodeNameMeaning
0SuccessThe command completed without error.
1General errorCatch-all: the program chose to signal failure (grep: no match; many tools: any error).
2Misuse of shell builtin / usage errorBash: wrong arguments to a builtin. grep: an error occurred (not just no match). Many CLIs: bad usage.
64EX_USAGECommand line usage error (sysexits.h).
65EX_DATAERRInput data was incorrect.
66EX_NOINPUTInput file did not exist or was unreadable.
67EX_NOUSERUser does not exist.
68EX_NOHOSTHost does not exist.
69EX_UNAVAILABLEService unavailable.
70EX_SOFTWAREInternal software error.
71EX_OSERROS error (fork failed, etc.).
72EX_OSFILECritical OS file missing.
73EX_CANTCREATCannot create output file.
74EX_IOERRInput/output error.
75EX_TEMPFAILTemporary failure; retry later (mail systems).
76EX_PROTOCOLRemote error in protocol.
77EX_NOPERMPermission denied.
78EX_CONFIGConfiguration error.
100Debian apt / dpkg errorapt-get: a package operation failed. Also Python: nothing standard.
125Docker: daemon errordocker run itself failed (bad option, image not found). Also xargs: command killed by signal / other failures.
126Command cannot executeFound but not executable (permission denied, or a directory). Also Docker: contained command cannot be invoked.
127Command not foundThe shell could not find the program on PATH (typo, missing package, wrong shebang).
128Invalid exit argumentexit called with a value outside 0–255.
129Killed by SIGHUP (128+1)Terminal hung up or daemon reload signal.
130Killed by SIGINT (128+2)Ctrl-C.
131Killed by SIGQUIT (128+3)Ctrl-\ (core dump).
132Killed by SIGILL (128+4)Illegal instruction: corrupted binary or wrong CPU architecture.
133Killed by SIGTRAP (128+5)Debugger breakpoint.
134Killed by SIGABRT (128+6)abort(): assertion failure, glibc detected heap corruption, Go/Rust panic in some modes.
135Killed by SIGBUS (128+7)Bus error: misaligned access or a memory-mapped file that was truncated.
136Killed by SIGFPE (128+8)Arithmetic error, typically integer division by zero.
137Killed by SIGKILL (128+9)Forcibly killed: OOM killer (check dmesg), kill -9, Docker/Kubernetes memory limit, timeout -s KILL.
139Killed by SIGSEGV (128+11)Segmentation fault: invalid memory access.
141Killed by SIGPIPE (128+13)Wrote to a closed pipe, e.g. `cmd | head` after head exited.
143Killed by SIGTERM (128+15)Polite termination request: kill, systemctl stop, docker stop (after the grace period it becomes 137).
148Killed by SIGTSTP (128+20)Ctrl-Z (stopped, reported by some shells).
152Killed by SIGXCPU (128+24)CPU time limit exceeded (ulimit -t).
153Killed by SIGXFSZ (128+25)File size limit exceeded (ulimit -f).
255Exit status out of range / -1exit(-1) wraps to 255. ssh: connection or protocol error. rsync: unexplained error.

How exit codes work

Every process ends with an 8-bit status, 0 to 255. By convention 0 means success and anything else failure; the shell exposes it as $?, and &&, ||, if and set -e all branch on it. The number's meaning beyond zero/non-zero belongs to the program, with a few conventions that are nearly universal.

The shell's own codes

  • 126: the file was found but could not be executed. Missing execute bit, a directory, a binary for another architecture, or a noexec mount.
  • 127: not found. A typo, a program not installed, or a PATH that differs between your shell and the environment the script runs in (cron, systemd, Docker). Also a shebang line pointing at a missing interpreter, including \r\n line endings making /bin/bash\r.
  • 128 + n: the process died from signal n. The shell cannot return a signal directly, so it adds 128. 130 is Ctrl-C (SIGINT 2), 137 is SIGKILL (9), 139 is SIGSEGV (11), 143 is SIGTERM (15). The signals reference lists them all.

137 in containers

Exit 137 from a container is almost always the kernel's OOM killer or the container runtime enforcing a memory limit: the process was sent SIGKILL, which cannot be caught, so nothing was logged by the application. Check docker inspect for OOMKilled: true, dmesg for “Out of memory”, or Kubernetes events for OOMKilled. 143 is the normal result of docker stop or a pod termination when the process handled SIGTERM; 137 after a stop means it did not shut down within the grace period.

sysexits.h

BSD defined codes 64–78 for mail and system tools to report categories of failure (EX_USAGE 64, EX_NOINPUT 66, EX_TEMPFAIL 75…). Postfix, sendmail and some Perl and Go programs still use them; nothing else does, so treat them as a convention, not a rule.

Questions

What does exit code 1 mean?

A generic failure: the program decided something went wrong and did not have a more specific code. For grep it means no lines matched, which is not an error at all. Read the program’s stderr output, not the number.

Why do I get 127 in cron or systemd but not in my shell?

The PATH is different. Your shell’s profile adds directories such as /usr/local/bin or ~/.local/bin that cron and systemd do not see. Use absolute paths or set PATH at the top of the script.

What is the maximum exit code?

255. exit 256 wraps to 0, exit 300 becomes 44 (300 mod 256). Negative values wrap too: exit(-1) is 255.

How do I get the exit code of a pipeline?

By default $? is the last command’s status. set -o pipefail makes the pipeline fail if any stage fails, and the PIPESTATUS array in bash holds every stage’s code.