Exit status
lastmod 2023-03-02created 2023-03-021 edits
In computer programming, the exit status or return code of a process is a small number passed from a child process (callee) to a parent process (caller) when it has finished executing a specific procedure or delegated task. In DOS it is referred to as errorlevel.
AmigaOS
In AmigaOS, three levels are defined:
- WARN 5
- ERROR 10
- FAILURE 20
Shell
The exit status of an executed shell command is the value returned by the waitid system call or an equivalent function.
For the shell's purposes, a command that ends with exit status 0 means success. A nonzero exit status indicates failure. When a command is terminated by a signal with number N, the shell sets the variable $? to a value greater than 128. Most shells use 128+N, but ksh93 uses 256+N.
| Exit Code Number | Meaning | Example | Comments |
| 1 | Catchall for general errors | | Miscellaneous errors, such as "divide by zero" and other impermissible operations |
| 2 | Misuse of shell builtins (according to Bash documentation) | | Missing keyword or command, or permission problem (and diff return code on a failed binary file comparison). |
| 126 | Command invoked cannot execute | | Permission problem or command is not an executable |
| 127 | "command not found" | | Possible problem with $PATH or a typo |
| 128 | Invalid argument to exit | | exit takes only integer args in the range 0 - 255 (see first footnote) |
| 128+n | Fatal error signal "n" | | $? returns 137 (128 + 9) |
| 130 | Script terminated by Control-C | Ctl-C | Control-C is fatal error signal 2, (130 = 128 + 2, see above) |
| 255 | Exit status out of range | | exit takes only integer args in the range 0 - 255 |
C language
The C programming language lets programs return or exit from the main function by returning the EXIT_SUCCESS and EXIT_FAILURE macros, or by providing a success or failure signal. On Unix-like operating systems these refer to 0 and 1 respectively. A C program can also exit by specifying an integer status or an exit macro as the first argument to the exit() function.
DOS
In DOS terminology, errorlevel is an integer exit code returned by an executed program or function. Errorlevel generally ranges from 0 to 255. In DOS only 256 error codes are available.
Java
In Java, any method can call System.exit(int status), to the extent the security manager allows. This terminates the currently running Java virtual machine. A nonzero status code indicates abnormal termination.[2]
OpenVMS
In OpenVMS, success is recognized by odd values and failure by even values.
POSIX
POSIX-compatible operating systems generally treat 0 as success and nonzero as an error.
Windows
Windows uses a 32-bit singed integer as the exit code. If a process fails to initialize, a Windows system error code is returned.
The exit code is referenced directly, for example by the command-line interpreter CMD.EXE, using the term errorlevel inherited from DOS. .NET Framework processes and Windows PowerShell refer to it through the ExitCode property of the Process object.