exit code
A number a process returns when it finishes: 0 means success, anything else means something went wrong.
In more detail
Shells, scripts and automation tools all read it to decide whether a step worked. It says only whether a command succeeded, not whether it changed anything.
Examples
The command module reports it as rc; rc=0 means the command succeeded.An exit code of 0 after SIGTERM shows a handled, graceful stop; a code of -15 in Python means the process was killed by signal 15.docker inspect exit-demo --format '{{.State.ExitCode}}'A Git hook that exits with a non-zero code stops the commit.git commit -m 'wip logging' 2>&1; echo "exit code $?"os.Exit(2) // misused command lineThe kernel keeps a finished child's exit status until its parent collects it, and the shell shows the last one in $?. A process ended by a signal reports 128 plus the signal number in the shell, so 143 means SIGTERM and 137 means SIGKILL. Recording the exit state of a status command is part of good diagnostic evidence.pytest exits with a non-zero code when any test fails.The reconnection gate keeps a host quarantined when the validator exits non-zero.In Terraform: Pipelines decide whether a step passed by its exit code. terraform fmt -check returns a non-zero code when files need formatting, which fails the job. A green job only means every command returned zero, so make sure each command checks what you care about.Related terms
- command module — The module that runs any program you name on the host and reports what it printed, without being able to tell whether it changed anything.
- register — The task keyword that saves a task's result in a named variable so later tasks can read it.
- exit builtin — The builtin that ends the shell or script immediately with a chosen exit status, 0 for success.
- if statement — A statement that runs a block of code only when a condition holds, optionally with an else block for when it does not.
- AND list — Two commands joined by &&, where the second runs only if the first succeeds.
- OR list — Two commands joined by ||, where the second runs only if the first fails.
- set -e — The shell option that makes a script exit as soon as a command fails, instead of carrying on.
- step (GitHub Actions) — One task inside a job, either a shell command under run or an action called with uses.
- SIGTERM — The signal that politely asks a process to finish its work and exit.
- graceful shutdown — Stopping a service in an orderly way: finish current work, close connections, then exit.
- container status — The current state of a container as Docker reports it, such as created, running, exited or restarting.
- SIGKILL — The signal that ends a process immediately; it cannot be caught or ignored.
- OOM killer — The part of the Linux kernel that kills a process when memory runs out.
- Git hook — A script Git runs automatically at a point in its workflow, such as pre-commit, which can stop the commit by exiting non-zero.
- process — A program that is currently running, with its own memory and a numeric identifier.
- parent process — The process that started another process; every process except the first records its parent's PID.
- signal — A short notification the kernel delivers to a process, such as please stop or stop now.
- subprocess module — The standard library module for running other programs from Python and collecting their output and exit code.
- security gate — An automated check in a pipeline that stops a change going further when it fails, usually by exiting with a non-zero code.
- Trivy — An open-source scanner that finds vulnerable packages, secrets and misconfigurations in repositories, container images, Kubernetes manifests and Terraform.
- terraform fmt — The command that rewrites .tf files into Terraform's one standard layout; it never looks at real infrastructure.
- pipeline — An automated sequence of steps, such as build, test, scan and publish, that runs on every change.
Taught in
- Your First Ad Hoc Command — Ansible Configuration Management at Scale
- Connections And Privilege Escalation — Ansible Configuration Management at Scale
- Modules And Idempotency — Ansible Configuration Management at Scale
- The Unquoted Variable: Splitting And Globbing — Bash Scripting & Command Line Automation
- Exit Codes, And What Success Means — Bash Scripting & Command Line Automation
- Conditionals: test, Brackets, Double Brackets, case — Bash Scripting & Command Line Automation
- Functions, local And declare — Bash Scripting & Command Line Automation
- Option Parsing With getopts — Bash Scripting & Command Line Automation
- set -e, set -u And pipefail: Promises And Traps — Bash Scripting & Command Line Automation
- trap, Cleanup And Temporary Files — Bash Scripting & Command Line Automation
- ShellCheck — Bash Scripting & Command Line Automation
- Scheduling, Monitoring And A Script That Reports — Bash Scripting & Command Line Automation
- What Is a Pipeline? — Continuous Integration & Continuous Delivery Pipelines
- Runners: Where Code Executes — Continuous Integration & Continuous Delivery Pipelines
- Scaling with Matrix Builds — Continuous Integration & Continuous Delivery Pipelines
- Probes And Health Checks — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Requests, Limits And Quotas — Certified Kubernetes Application Developer (CKAD) Exam Prep
- Pre-Commit Secret Scanning with Gitleaks & Entropy — Cloud Security & DevSecOps Engineering
- Software Composition Analysis with Trivy — Cloud Security & DevSecOps Engineering
- Static IaC Scanning: Linting Terraform with Checkov — Cloud Security & DevSecOps Engineering
- Enforcing OPA Guardrails on Terraform Plan Payloads — Cloud Security & DevSecOps Engineering
- Continuous IaC Drift Detection & State Protection — Cloud Security & DevSecOps Engineering
- Disposability, Dev Prod Parity And Logs — DevOps & Site Reliability Engineering
- Run, Stop, Restart And Remove A Container — Docker Architecture & Production Containers
- Commands, Logs, Exec And Exit Codes — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Port Publishing, Localhost And Network Troubleshooting — Docker Architecture & Production Containers
- Environment, Secret Files And Runtime Restrictions — Docker Architecture & Production Containers
- Health Checks, Dependencies And Reliable Startup — Docker Architecture & Production Containers
- Integration Tests, Test Data And Compose Cleanup — Docker Architecture & Production Containers
- Diagnose Crashes, Resource Limits And Unhealthy Containers — Docker Architecture & Production Containers
- Build, Test And Promote The Same Image In CI — Docker Architecture & Production Containers
- Harden And Deliver The Complete Service Stack — Docker Architecture & Production Containers
- Conventional Commits — Advanced Git Internals & Distributed Workflows
- Your First Program and go run — Concurrent Systems Programming with Go
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- The Standard testing Package — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go
- Parsing Arguments with flag — Concurrent Systems Programming with Go
- Handling Timeouts and Errors — Concurrent Systems Programming with Go
- Exporting Results as JSON — Concurrent Systems Programming with Go
- Containerizing and Testing the Final Build — Concurrent Systems Programming with Go
- Troubleshooting: describe, Events And A First Smoke Test — Kubernetes: Production-Grade Container Orchestration
- Troubleshooting: Probes, Logs, exec And CrashLoopBackOff — Kubernetes: Production-Grade Container Orchestration
- Troubleshooting: OOMKilled, Throttling And Evictions — Kubernetes: Production-Grade Container Orchestration
- What A Kernel Does, And What It Refuses To Do — Linux Fundamentals & Systems Administration
- The Diagnostic Ladder: Is It Up, Is It Named, Is It Routed — Linux Fundamentals & Systems Administration
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Child Processes: spawn, execFile, fork & IPC — Node.js Internals & Backend Services
- Global Error Trapping: uncaughtException & Exits — Node.js Internals & Backend Services
- A Standard Library Tour — Hands-on Python: Complete Video Course & Book
- Testing With pytest — Hands-on Python: Complete Video Course & Book
- Recovery & System Validation Testing — Security Operations & Threat Hunting (SOC)
- Container Security: Minimal Bases And Non Root — Application Security & Threat Modeling for Engineers
- Image Scanning And Trivy — Application Security & Threat Modeling for Engineers
- Installing Terraform And Meeting The CLI — Infrastructure as Code with Terraform
- Running Terraform In CI — Infrastructure as Code with Terraform
- Reading A Plan, Saving It, Applying It — HashiCorp Terraform Associate (004) Exam Prep
- Validate, Format, Destroy, And The Flags That Bend A Plan — HashiCorp Terraform Associate (004) Exam Prep
- Input Variables, Outputs, And Which Value Wins — HashiCorp Terraform Associate (004) Exam Prep
- Drift: When Reality Stops Matching State — HashiCorp Terraform Associate (004) Exam Prep
- Conditionals: register, when, changed_when And failed_when — RHCE in Ansible (EX294): Automate Red Hat Systems
References
- docker container run reference: exit status
- Bash Reference Manual: Exit Status
- bash(1) manual page: exit status
- POSIX exit()
- POSIX: Shell Command Language (exit status)
- man7: wait(2)
- sys.exit
- man7.org: exit(3)
- terraform fmt command