/ˈɛɡ.zɪt koʊd/
noun — “the numeric truth a program leaves behind when it dies.”
Exit Code is a small integer returned by a program to its parent process upon termination. It communicates whether the program completed successfully, encountered an error, or experienced a specific failure condition. In information technology, Exit Codes are the silent reporters of program health, letting scripts, shells, and orchestration tools make decisions without reading verbose logs.
By convention, a zero Exit Code signals success, while any non-zero value indicates some form of failure. Some systems reserve specific ranges for certain types of errors: misusage, file not found, permission denied, or even custom application-defined errors. The key is that Exit Codes are standardized enough for automation yet flexible enough to carry context.
In shell scripting and Command Line Interface workflows, Exit Codes are central to error handling. Conditional statements often evaluate the exit status of the previous command (`$?` in Unix shells) to decide whether to continue, retry, or abort a process. Pipelines, background jobs, and monitoring scripts all rely on exit codes to behave predictably without human intervention.
Advanced usage includes mapping Exit Codes to logging and alerting systems. For instance, a script might redirect error messages to Standard Error while sending successful results to Standard Output. Supervisors, daemons, and CI/CD pipelines use the numeric value alone to trigger notifications, restarts, or escalation procedures. This makes Exit Codes a lightweight but powerful communication channel.
In programming languages, Exit Codes are often wrapped in API calls or runtime methods. Developers might throw exceptions or set status codes before terminating the process. Regardless of the language, the OS interprets the final numeric value to maintain compatibility with scripts and external tools. In other words, Exit Codes are the lingua franca between programs and the systems that run them.
Misinterpreting Exit Codes can lead to subtle bugs. A program may succeed according to its own logic but return a non-zero code unintentionally, causing orchestration tools to panic unnecessarily. Careful design ensures that each Exit Code accurately reflects the program’s outcome, maintaining trust between processes and their overseers.
Exit Code is like leaving a polite note for the next process: “I’m fine, carry on,” or “Something broke, handle with care.”
See Process Management, Standard Output, Standard Error, Logging, Monitoring.