Linux Exit Codes and POSIX Signals (0-255): Complete Diagnostic Table and Debugging Guide

Last Verified On: Kernel 6.8 / 6.12 LTS / Ubuntu 24.04 LTS & Debian 12/13 Safe (Read-Only) Exit Code: 137 / 139 / 143 / 126 / 127

Direct Answer / TL;DR

Codes above 128 are shell-converted signal deaths (128+signal): 137=SIGKILL (OOM or kill -9), 139=SIGSEGV, 143=SIGTERM, while 126/127 mean exec-permission or missing-command failures in cron and systemd PATHs. Diagnose with coredumpctl, journalctl -g, and docker/podman inspect OOMKilled; then fix PATH entries, unit resource limits, and core_pattern routing on Ubuntu 24.04, Debian 12, and RHEL 9.

journalctl -b --no-pager -g 'Main process exited'

Core Architecture & Mechanics

Every terminating process leaves a 32-bit wait status with the kernel, collected by the parent via wait()/wait4() or waitid(). The encoding is exact: bits 0-6 hold the termination signal number, bit 7 is the dumped-core flag, and bits 8-15 hold the 8-bit exit code. libc decodes this with WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, and WCOREDUMP. The critical subtlety: the kernel never returns a literal “137”. Shells synthesize $? = 128 + WTERMSIG when WIFSIGNALED is true. A SIGKILL death is raw wait status 0x0009; the shell prints 137. Exit code 137 is a shell-layer convention, not a kernel value. strace -e trace=exit_group /bin/true proves the distinction: a voluntary exit shows exit_group(0); a SEGV death shows a signal event and no exit_group.

Rules for $? that break pipelines in production. It is overwritten by every command, so capture it immediately: app; rc=$?. Background PIDs require wait "$pid". Pipelines default to the last member; set -o pipefail makes the highest failure win, and bash’s ${PIPESTATUS[@]} exposes every member (zsh: $pipestatus; dash and BusyBox ash have neither — restructure with pipefail plus $?). Classic masked failure: yes | head -c1 >/dev/null; echo ${PIPESTATUS[@]} prints 141 0 — the upstream writer died of SIGPIPE while default $? claimed success from head.

Reserved band. 0 is success. 1 is the generic failure. 2 is builtin misuse (bash [ foo syntax errors) and the Nagios CRITICAL convention. 126 is execve returning EACCES: the path exists but is not executable. 127 is execve returning ENOENT: unknown command, stripped PATH, or a shebang interpreter that does not exist. 128 is bash internal (“numeric argument required”). 129-191 are reserved by the 128+N signal convention — an application that voluntarily emits, say, 143 is indistinguishable from a SIGTERM death and lies to tooling. 255 is the wraparound clamp plus ssh’s own transport-failure code.

Signal machinery. man 7 signal defines per-signal default dispositions: Term, Ign, Core, Stop, Cont. Core-producing defaults on x86-64 Linux are QUIT, ILL, TRAP, ABRT, BUS, FPE, SEGV, plus XCPU, XFSZ, and SYS when rlimits/seccomp trigger. SIGKILL (9) and SIGSTOP (19) cannot be caught, blocked, or ignored. SIGPIPE (13) defaults to Terminate but long-running daemons routinely ignore it. Coredump capture is gated by RLIMIT_CORE (ulimit -c) and /proc/sys/kernel/core_pattern: an absolute path writes plain core files, and a |/usr/lib/systemd/systemd-coredump ... pipe streams compressed coredumps into /var/lib/systemd/coredump with journald registration. Ubuntu ships apport, which rewrites kernel.core_pattern at service start and lands records in /var/crash instead.

OOM path. Under cgroup memory.max pressure the kernel OOM killer selects the highest-RSS task and SIGKILLs it; the OCI runtime records OOMKilled: true with exit 137, and kubelet surfaces reason OOMKilled in containerStatuses[].lastState.terminated. systemd unit accounting lands in journald as Main process exited, code=killed, status=9/KILL with ExecMainCode (exited|killed) and ExecMainStatus retrievable per unit.

Truncation and wraparound. The kernel reports only the low byte: bash -c 'exit 300'; echo $? # 44. Negative values wrap: bash -c 'exit -1'; echo $? # 255. Clamp application-defined codes to 0-78 and never touch 129-191 or 255.

bash -c 'exit 300'; echo $?            # 44  <- low-byte truncation
bash -c 'exit -1'; echo $?             # 255 <- wraparound
bash -c 'exit garbage'; echo $?        # 128 <- bash: numeric argument required
sh -c 'totally-missing-cmd'; echo $?   # 127 <- execve: ENOENT
/etc/passwd; echo $?                   # 126 <- execve: EACCES
yes | head -c1 >/dev/null; echo ${PIPESTATUS[@]}   # 141 0 (SIGPIPE masked upstream)
sleep 30 & p=$!; kill -TERM "$p"; wait "$p"; echo $?  # 143
strace -e trace=exit_group sh -c 'exit 44' 2>&1 | grep exit_group   # exit_group(44)

Complete Reference Table / Diagnostic Matrix

Three stacked layers: reserved/systemic codes, application conventions, and signal deaths. The exit-code column for signals assumes the universal 128+N shell synthesis (bash, dash, ash, zsh).

Item / Code / FlagBehaviorCommon Cause / Use Case
0SuccessNormal completion; monitoring checks: 0 = OK.
1Generic failureMost apps’ default error; grep with zero matches; false.
2CLI misuse / app-definedbash builtin syntax errors; POSIX ls on a missing directory; make recipe failure; Nagios CRITICAL.
3App-definedNagios UNKNOWN; various daemons’ config-error code.
32Partial mount failuremount -a reports failed /etc/fstab entries (status is a sum of per-target results).
64-78sysexits.h EX_* conventions64 EX_USAGE bad args; 65 EX_DATAERR; 66 EX_NOINPUT; 67 EX_NOUSER; 68 EX_NOHOST; 69 EX_UNAVAILABLE; 70 EX_SOFTWARE; 71 EX_OSERR; 72 EX_OSFILE; 73 EX_CANTCREAT; 74 EX_IOERR; 76 EX_PROTOCOL; 77 EX_NOPERM; 78 EX_CONFIG. Mailers and monitoring plugins.
75EX_TEMPFAILTemporary failure: the caller should retry (MTA queue semantics).
124timeout(1) firedtimeout killed the child after its duration; child’s own status hidden unless --preserve-status.
125OCI runtime failuredocker/podman failed before container start: bad image, port bind conflict, exec error.
126execve: EACCESMissing +x bit, noexec-mounted filesystem, unreadable interpreter.
127execve: ENOENTUnknown command; cron’s stripped PATH (default /usr/bin:/bin); broken shebang interpreter.
128bash internalexit given a non-numeric argument.
129-191128+N signal deathsReserved by shells for signal deaths (see rows below); apps must not emit these voluntarily.
255ssh transport / clampssh’s own code when the connection fails; also exit -1 wraparound; masks the remote command’s status.
SIGHUP 1 → 129Terminate (catchable)Terminal hangup; convention: kill -HUP daemon reload (nginx).
SIGINT 2 → 130TerminateCtrl-C interrupt of the foreground job.
SIGQUIT 3 → 131CoreCtrl-; deliberate core capture for debugging.
SIGILL 4 → 132CoreIllegal instruction: binary built for a newer ISA than the host CPU, corrupted image.
SIGTRAP 5 → 133CoreBreakpoint event under ptrace.
SIGABRT 6 → 134Coreabort(): failed assertion, malloc heap-corruption aborts, uncaught C++ exception via std::terminate.
SIGBUS 7 → 135Coremmap access past file end; failed NBD/network block device.
SIGFPE 8 → 136CoreInteger divide-by-zero or arithmetic overflow trap.
SIGKILL 9 → 137Terminate, uncatchableOOM killer (OOMKilled), kill -9, docker stop grace expiry, watchdogs.
SIGUSR1 10 → 138Terminate / app-definedApplication-defined (nginx: reopen log files).
SIGSEGV 11 → 139CoreInvalid memory access: wild pointer, ABI-mismatched library, corrupted binary.
SIGUSR2 12 → 140Terminate / app-definedApplication-defined (dockerd: goroutine stack dump).
SIGPIPE 13 → 141TerminateWrite to a closed pipe/socket; daemons routinely ignore it.
SIGALRM 14 → 142Terminatealarm()/setitimer expiry; internal watchdogs.
SIGTERM 15 → 143TerminateDefault polite kill: systemd stop, kubelet graceful container termination.
SIGSTKFLT 16 → 144TerminateLinux-only stack fault; effectively unused.
SIGCHLD 17 → 145Ignore defaultChild state-change notification; default ignored.
SIGCONT 18 → 146ContinueResume a stopped process.
SIGSTOP 19 → 147Stop, uncatchableAdministrative suspend (kill -STOP).
SIGTSTP 20 → 148StopCtrl-Z terminal stop.
SIGTTIN 21 → 149StopBackground process read from controlling tty.
SIGTTOU 22 → 150StopBackground process write to tty (stty tostop).
SIGURG 23 → 151Ignore defaultUrgent socket condition.
SIGXCPU 24 → 152CoreCPU-time rlimit breach (ulimit -t, LimitsCPU=).
SIGXFSZ 25 → 153CoreFile-size rlimit breach (ulimit -f, LimitsFSIZE=).
SIGVTALRM 26 → 154TerminateVirtual CPU-time timer expiry.
SIGPROF 27 → 155TerminateProfiling timer expiry.
SIGWINCH 28 → 156Ignore defaultTerminal resize event.
SIGIO 29 → 157TerminateAsync I/O event flag.
SIGPWR 30 → 158TerminatePower failure (UPS daemons).
SIGSYS 31 → 159CoreBad syscall; seccomp ACT_KILL on default container profiles → exit 159.
SIGRTMIN-SIGRTMAX 34-64 → 162-192TerminateApplication real-time signals; glibc reserves the first RT signals internally — resolve bounds with kill -l RTMIN/kill -l RTMAX.

High-frequency tool exit codes worth memorizing:

Item / Code / FlagBehaviorCommon Cause / Use Case
grep 1No matchSilent pipeline exit-masker; pair with pipefail.
diff 1Files differIntentional comparison result, not an error.
curl 7 / 28 / 22 / 35 / 60Connect refused / timeout / -f HTTP >= 400 / TLS handshake / CA verifyNetwork and TLS triage ladder.
rsync 23 / 24 / 30Partial transfer / vanished source / data timeout23 alerts; 24 is usually benign source churn; 30 tune --timeout.
ssh 255Transport failureConnection died before a remote status existed; fetch remote rc explicitly.
mount 32fstab mount(s) failedAggregate status of per-target failures.

Multi-Distro Implementation Differences

Exit-status semantics are identical everywhere; the differences are core-dump routing, debug-symbol tooling, and default service environments.

Ubuntu / Debian

systemctl show docker -p ExecMainCode -p ExecMainStatus
journalctl -b --no-pager -g 'oom-killer|Out of memory' | tail -n 15
sysctl kernel.core_pattern        # Ubuntu: apport rewires this at boot
ls -lh /var/crash/ 2>/dev/null    # apport crash records (.crash)
coredumpctl list --no-pager 2>&1 | tail -n 5   # needs systemd-coredump pkg
code class=

RHEL / AlmaLinux / Rocky

systemctl show sshd -p ExecMainCode -p ExecMainStatus
rpm -q systemd-coredump abrt
coredumpctl list --no-pager | tail -n 10
ausearch -m avc,seccomp -ts today | tail -n 20   # SELinux AVC + seccomp denials
dnf debuginfo-install <package>                  # symbols for 139 post-mortems

Arch Linux

coredumpctl list --no-pager --since=today
coredumpctl info <pid-or-name> | sed -n '1,12p'
coredumpctl debug <name>         # gdb prompt: thread apply all bt full
sysctl kernel.core_pattern       # |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h

Alpine / Containers

set -o pipefail; dmesg | grep -iE 'oom|killed process' | head; echo $?
ulimit -c                       # containers usually ship with 0
docker inspect --format 'exit={{.State.ExitCode}} oom={{.State.OOMKilled}}' <ctr>
# no systemd: no coredumpctl; host core_pattern must point to a real file path

Common Failure Modes & Troubleshooting Recipes

1. Container death with exit 137. First separate OOM from an external kill -9 or expired stop grace:

docker inspect --format 'exit={{.State.ExitCode}} oom={{.State.OOMKilled}} err={{.State.Error}}' <ctr>
journalctl -k -b --no-pager | grep -E 'Out of memory|oom-killer' | tail -n 20
kubectl get pod <pod> -o jsonpath='{.status.containerStatuses[0].lastState.terminated}'

OOMKilled: true means raise --memory/memory.max or fix the leak. A controlled, safe reproduction (confined by cgroup limit — install stress-ng via the package manager first):

systemd-run --scope -p MemoryMax=64M stress-ng --vm 1 --vm-bytes 256M --timeout 30s
journalctl -k --no-pager -g 'Out of memory' | tail -n 10   # confirm the oom-kill entry

2. Exit 139 (SIGSEGV) post-mortem.

journalctl -b --no-pager -g 'segfault at'
coredumpctl info <name> --no-pager | sed -n '/Signal/,+8p'
coredumpctl debug <name>        # then: thread apply all bt full

Symbols: Debian/Ubuntu apt install libc6-dbg, RHEL dnf debuginfo-install <package>, Arch ships symbolified systemd coredumps directly. Alpine in containers needs --ulimit core=-1 plus a writable host-side kernel.core_pattern.

3. Exit 126/127 from cron and systemd. Both run with stripped PATH (/usr/bin:/bin for cron; minimal manager env otherwise):

env -i /bin/sh -c 'echo $PATH'                        # reproduce the minimal env
grep -n 'PATH=' /etc/crontab                          # cron's default
systemctl cat <unit>.service | grep -i environment
# fix: absolute paths in crontab, or Environment=PATH=... in the unit drop-in
/etc/passwd; echo $?                                  # 126: exists, not executable

4. Exit 143 / unit stop policies. If the app treats SIGTERM as failure or needs longer to drain:

systemctl show <app> -p ExecMainStatus -p KillSignal -p TimeoutStopUSec
# /etc/systemd/system/<app>.service.d/tuning.conf
[Service]
SuccessExitStatus=143      # treat tunnelled TERM state as clean
TimeoutStopSec=25
Restart=on-failure
RestartPreventExitStatus=2 # exit 2 is terminal: do not restart-loop

5. Pipelines masking failures (141 and silent zeros). Default $? is the last member only:

set -o pipefail
curl -sf https://example.invalid/health | tee /tmp/health.xml; echo rc=$?  # rc=22, not tee's 0
yes | head -c1 >/dev/null; echo ${PIPESTATUS[@]}                            # 141 0

6. Post-mortem straight from journald. The decisive line format:

journalctl -b _SYSTEMD_UNIT=<app>.service -g 'Main process exited' --no-pager | tail -n 5
# code=killed, status=9/KILL      -> $? will read 137
# code=killed, status=11/SEGV     -> 139 (core flag visible via coredumpctl)
# code=exited,  status=1/FAILURE  -> plain exit(1)
systemctl show <app> -p ExecMainCode -p ExecMainStatus

Production Hardening & Safety Checklist

Safety Check: Every command above is read-only or simulation-grade. The only mutations involved in this workflow are kernel.core_pattern edits and systemd drop-ins. Record the current handler first with sysctl kernel.core_pattern, stage changes as /etc/sysctl.d/99-coredump.conf, and roll back by deleting that file and running sysctl --system; unit drop-ins roll back with systemctl revert <unit>. Never validate 137 by killing production daemons — use the confined systemd-run --scope sandbox shown above.

  • Propagate codes correctly: always wait "$pid" for background jobs, set -o pipefail in CI/monitoring scripts, and prefer ${PIPESTATUS[@]} (bash) over re-running logic.
  • Keep application exit codes at or below 78 (sysexits ceiling). Never emit 129-191 or 255 voluntarily — they collide with signal deaths and ssh’s transport code.
  • Unit hygiene: Restart=on-failure plus explicit SuccessExitStatus/RestartPreventExitStatus; pair LimitCORE=infinity with a verified core_pattern handler before relying on 139 post-mortems.
  • timeout(1): add --preserve-status when the child’s signal fate must surface instead of 124.
  • Container platforms: alert on OOMKilled, not bare 137 — a docker stop grace expiry also yields 137; set memory limits deliberately and export them to dashboards.
  • Coredumps may contain secrets and environment data: enable only with retention policy (ProcessSizeMax, JournalSizeMax in coredump.conf) on hosts handling credentials.

Frequently Asked Edge Cases

Why did my container exit 137 when the host shows no OOM kill?

137 is 128+SIGKILL; non-OOM sources include the runtime's stop-grace expiry (docker stop -t), watchdogs, or a manual kill -9. Confirm with docker inspect OOMKilled and check journalctl -k -g 'Out of memory' before assuming a memory limit problem.

Can an application legitimately return exit code 130 without receiving SIGINT?

Technically yes, but shells cannot distinguish exit(130) from a SIGINT death, which misleads monitoring and CI. Keep custom codes below 129 (POSIX/sysexits ceiling is 78) and reserve 128+N exclusively for signal deaths.

How do real-time signals map to exit codes?

SIGRTMIN (34) through SIGRTMAX (64) produce 162-192 via the 128+N convention. Never hardcode 34, because glibc reserves the first real-time signals internally — resolve bounds at runtime with kill -l RTMIN and kill -l RTMAX.

References & Upstream Docs

  1. Linux man-pages: man 7 signal, man 7 wait_status, man 1p exit (128+N note)
  2. Linux man-pages: man 3 sysexits (BSD heritage) and Nagios plugin development guidelines (0-3)
  3. systemd documentation: coredumpctl(1), systemd-coredump(8), systemd.exec(5) SuccessExitStatus/RestartPreventExitStatus/LimitCORE
  4. kernel documentation: /proc/sys/kernel/core_pattern, RLIMIT_CORE, cgroup v2 memory.max OOM semantics
  5. Docker/podman documentation: .State.OOMKilled, exit code 125/126/127 mapping

Related Concepts