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 line
The 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

Taught in

References

Certification courses