{{Short description|Integer number that is made available to the parent of a terminated process}} {{Redirect|Exit code|the prefix used to place an international telephone call|International direct dialing#International call prefix}} {{Redirect2|Result code|return code|the result code of software in general|error code}} {{Use dmy dates|date=January 2022|cs1-dates=y}} {{Use list-defined references|date=January 2022}}

In computing, the '''exit status''' (also '''exit code''' or '''exit value''') of a terminated process is an integer number that is made available to its parent process (or caller). In DOS, this may be referred to as an '''errorlevel'''.

When computer programs are executed, the operating system creates an abstract entity called a process in which the book-keeping for that program is maintained. In multitasking operating systems such as Unix or Linux, new processes can be created by active processes. The process that spawns another is called a ''parent process'', while those created are ''child processes''. Child processes run concurrently with the parent process. The technique of spawning child processes is used to delegate some work to a child process when there is no reason to stop the execution of the parent. When the child finishes executing, it exits by calling the ''exit'' system call. This system call facilitates passing the exit status code back to the parent, which can retrieve this value using the ''wait'' system call.

==Semantics== The parent and the child can have an understanding about the meaning of the exit statuses. For example, it is common programming practice for a child process to return (exit with) zero to the parent signifying success. Apart from this return value from the child, other information like how the process exited, either normally or by a signal may also be available to the parent process.

The specific set of codes returned is unique to the program that sets it. Typically it indicates success or failure. The value of the code returned by the function or program may indicate a specific cause of failure. On many systems, the higher the value, the more severe the cause of the error.<ref name="Woude_2007"/> Alternatively, each bit may indicate a different condition, with these being evaluated by the ''or'' operator together to give the final value; for example, fsck does this.

Sometimes, if the codes are designed with this purpose in mind, they can be used directly as a branch index upon return to the initiating program to avoid additional tests.

===AmigaOS=== In AmigaOS, MorphOS and AROS, four levels are defined: # {{mono|OK 0}} # {{mono|WARN 5}} # {{mono|ERROR 10}} # {{mono|FAILURE 20}}

===Shell and scripts=== Shell scripts typically execute commands and capture their exit statuses.

For the shell's purposes, a command which exits with a zero exit status has succeeded. A nonzero exit status indicates failure. This seemingly counter-intuitive scheme is used so there is one well-defined way to indicate success and a variety of ways to indicate various failure modes. When a command is terminated by a signal whose number is {{code|N}}, a shell sets the variable {{code|$?}} to a value greater than 128. Most shells use {{mono|128+N}}, while ksh93 uses {{mono|256+N}}.

If a command is not found, the shell should return a status of {{mono|127}}. If a command is found but is not executable, the return status should be {{mono|126}}.<ref name="OpenGroup_2015"/> Note that this is not the case for all shells.

If a command fails because of an error during expansion or redirection, the exit status is greater than zero.

===C language=== The C programming language allows programs exiting or returning from the main function to signal success or failure by returning an integer, or returning the macros <code>EXIT_SUCCESS</code> and <code>EXIT_FAILURE</code>. On Unix-like systems these are equal to 0 and 1 respectively.<ref name="glibc" /> A C program may also use the <code>exit()</code> function specifying the integer status or exit macro as the first parameter.

The return value from <code>main</code> is passed to the <code>exit</code> function, which for values zero, <code>EXIT_SUCCESS</code> or <code>EXIT_FAILURE</code> may translate it to "an implementation defined form" of ''successful termination'' or ''unsuccessful termination''.{{Citation needed|date=May 2023}}

Apart from zero and the macros <code>EXIT_SUCCESS</code> and <code>EXIT_FAILURE</code>, the C standard does not define the meaning of return codes. Rules for the use of return codes vary on different platforms (see the platform-specific sections).

===DOS=== In DOS terminology, an '''errorlevel''' is an integer exit code returned by an executable program or subroutine. Errorlevels typically range from {{mono|0}} to {{mono|255}}.<ref name="Paul_1997_BATTIPS"/><ref name="FD_2003_Errorlevel"/><ref name="Paul_1997_NWDOSTIP"/><ref name="Allen_2005"/> In DOS there are only 256 error codes available, but DR&nbsp;DOS 6.0 and higher support 16-bit error codes at least in {{mono|CONFIG.SYS}}.<ref name="Paul_1997_NWDOSTIP"/> With 4DOS and DR-DOS {{mono|COMMAND.COM}}, exit codes (in batchjobs) can be set by {{mono|EXIT ''n''}}<!-- MS-DOS/PC DOS COMMAND.COM does not support the optional parameter, just EXIT without any arguments --><ref name="Paul_1997_NWDOSTIP"/> and (in {{mono|CONFIG.SYS}}) through {{mono|ERROR=''n''}}<!-- and a number of other more specialized directives -->.<ref name="Paul_1997_NWDOSTIP"/>

Exit statuses are often captured by batch programs through {{mono|IF ERRORLEVEL}} commands.<ref name="Paul_1997_BATTIPS"/><ref name="Paul_1997_NWDOSTIP"/> Multiuser DOS supports a reserved <!-- true -->environment variable %ERRORLVL% which gets automatically updated on return from applications. {{mono|COMMAND.COM}} under DR-DOS 7.02 and higher supports a similar pseudo-environment variable {{mono|%ERRORLVL%}} as well as {{mono|%ERRORLEVEL%}}.<!-- MS-DOS and PC DOS do not, only Windows does! --> In {{mono|CONFIG.SYS}}, DR&nbsp;DOS 6.0 and higher supports {{mono|ONERROR}} to test the load status and return code of device drivers and the exit code of programs.<ref name="Paul_1997_NWDOSTIP"/>

===Java=== In Java, any method can call <code>System.exit(int status)</code>, unless a security manager does not permit it. This will terminate the currently running Java Virtual Machine. "The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination."<ref name="Java"/>

===OpenVMS=== In OpenVMS, success is indicated by odd values and failure by even values. The value is a 32-bit integer with sub-fields: control bits, facility number, message number and severity. Severity values are divided between success (Success, Informational) and failure (Warning, Error, Fatal).<ref name="OpenVMS"/>

===Plan 9=== In Plan 9's C, exit status is indicated by a string passed to the {{mono|exits()}} function, and function {{mono|main()}} is type {{mono|void}}.

===POSIX=== In Unix and other POSIX-compatible systems, the parent process can retrieve the exit status of a child process using the <code>wait()</code> family of system calls defined in POSIX header {{code|<wait.h>}}.<ref name="BD_syswait"/> Of these, the <code>waitid()</code><ref name="SH_waitid"/> call retrieves the full exit status, but the older <code>wait()</code> and <code>waitpid()</code><ref name="SH_wait"/> calls retrieve only the least significant 8 bits of the exit status.

The <code>wait()</code> and <code>waitpid()</code> interfaces set a ''status'' value of type <code>int</code> packed as a bitfield with various types of child termination information. If the child terminated by exiting (as determined by the <code>WIFEXITED()</code> macro; the usual alternative being that it died from an uncaught signal), SUS specifies that the low-order 8 bits of the exit status can be retrieved from the status value using the <code>WEXITSTATUS()</code> macro.

In the <code>waitid()</code> system call (added with SUSv1), the child exit status and other information are no longer in a bitfield but in the structure of type <code>siginfo_t</code>.<ref name="OpenGroup"/>

POSIX-compatible systems typically use a convention of zero for success and nonzero for error.<ref name="ExitStatus"/> Some conventions have developed as to the relative meanings of various error codes; for example GNU recommend that codes with the high bit set be reserved for serious errors.<ref name="glibc"/>

BSD-derived OS's have defined an extensive set of preferred interpretations: Meanings for 15 status codes 64 through 78 are defined in POSIX header {{code|<sysexits.h>}}.<ref name="FreeBSD"/> These historically derive from sendmail and other message transfer agents, but they have since found use in many other programs.<ref name="sysexits"/> It has been deprecated and its use is discouraged.<ref name="FreeBSD"/>

The Advanced Bash-Scripting Guide has some information on the meaning of non-0 exit status codes.<ref name="SpecialMeanings"/>

===VM/CMS===

{| class="wikitable" ! Return Code !! Meaning |- | 0 || Successful completion |- | 1 || Minor warning or informational condition |- | 2 || Warning, but command completed |- | 4 || Minor error, command completed with issues |- | 8 || Error occurred |- | 12 || Serious error |- | 16 || Severe error / command failed |- | 20+ || Command-specific severe errors |} <ref>{{Cite web |title=Return Codes |url=https://www.ibm.com/docs/en/zvm/7.4.0?topic=sc-return-codes |access-date=2026-03-27 |website=www.ibm.com |language=en-us}}</ref>

===Windows=== Microsoft Windows uses 32-bit unsigned integers as exit codes,<ref name="ExitProcess" /><ref name="GetExitCodeProcess" /> although the command interpreter treats them as signed.<ref name="ExitCodesBig" />

Exit codes are directly referenced, for example, by the command line interpreter CMD.exe in the <code>errorlevel</code> terminology inherited from DOS. The .NET Framework processes and the Windows PowerShell refer to it as the <code>ExitCode</code> property of the <code>Process</code> object.

==See also== * Error code * Return statement * true and false (commands)

==References== <references>

<ref name="Paul_1997_NWDOSTIP">{{cite book |title=NWDOS-TIPs&nbsp;— Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds |work=MPDOSTIP |author-first=Matthias R. |author-last=Paul |date=1997-07-30 |orig-date=1994-05-01 |edition=3 |version=Release 157 |language=de |url=http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm |access-date=2014-08-06 |url-status=live |archive-url=https://web.archive.org/web/20161104235829/http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm |archive-date=2016-11-04}} (NB. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. The provided link points to a HTML-converted version of the file, which is part of the <code>MPDOSTIP.ZIP</code><!-- still named TIPS_MP.ZIP between 1991 and 1996-11 --> collection.) [https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip<!-- A yet older version 155 from 1997-05-13 of the 1997-07-15 distribution archive. -->]</ref> <ref name="Paul_1997_BATTIPS">{{cite book |title=BATTIPs&nbsp;— Tips & Tricks zur Programmierung von Batchjobs |at=7: ERRORLEVEL abfragen |work=MPDOSTIP |author-first=Matthias R. |author-last=Paul |date=1997-05-01 |orig-date=1993-10-01 |language=de |url=http://www.antonis.de/dos/batchtut/battips/index.htm#7 |access-date=2017-08-23 |url-status=live |archive-url=https://web.archive.org/web/20170823191411/http://www.antonis.de/dos/batchtut/battips/index.htm |archive-date=2017-08-23 }} [https://www.auersoft.eu/soft/by-others/dos-exitcodes-de.html] [https://www.auersoft.eu/soft/by-others/dos-exitcodes-en.html] {{Webarchive|url=https://archive.today/20170911103337/https://www.auersoft.eu/soft/by-others/dos-exitcodes-en.html |date=2017-09-11 }} (NB. BATTIPS.TXT is part of MPDOSTIP.ZIP. The provided link points to a HTML-converted older version of the BATTIPS.TXT file.) [https://web.archive.org/web/20190601152204/https://www.sac.sk/download/text/mpdostip.zip<!-- A yet older version 155 from 1997-05-13 of the 1997-07-15 distribution archive. -->]</ref> <ref name="FD_2003_Errorlevel">{{cite web |title=MS-DOS errorlevels |author-first1=Eric |author-last1=Auer |author-first2=Matthias R. |author-last2=Paul |author-first3=Jim |author-last3=Hall |author-link3=Jim Hall (programmer) |date=2015-12-24 |orig-date=2003-12-31 |url=http://www.freedos.org/technotes/technote/207.html |url-status=dead |archive-url=https://web.archive.org/web/20151224202118/http://www.freedos.org/technotes/technote/207.html |archive-date=2015-12-24}}</ref> <ref name="Allen_2005">{{cite web |author-first1=William |author-last1=Allen |author-first2=Linda |author-last2=Allen |title=Windows 95/98/ME ERRORLEVELs |url=http://www.allenware.com/mcsw/errorlevels.zip |url-status=dead |archive-url=https://web.archive.org/web/20110707113138/http://www.allenware.com/mcsw/errorlevels.zip |archive-date=2011-07-07}}</ref> <ref name="OpenGroup_2015">{{cite web |title=Shell command language - Exit Status for commands |url=http://pubs.opengroup.org/onlinepubs/9699919799//utilities/V3_chap02.html#tag_18_08_02 |publisher=The Open Group |access-date=2015-07-07}}</ref> <ref name="glibc">{{cite web |url=https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html |title=The GNU C Library Reference Manual 25.6.2: Exit Status |publisher=Gnu.org |access-date=2012-07-09}}</ref> <ref name="Java">{{cite web |url=http://java.sun.com/javase/6/docs/api/java/lang/System.html#exit(int) |title=Java 1.6.0 API |publisher=Sun Microsystems |access-date=2008-05-06}}</ref> <ref name="OpenVMS">{{cite web |url=http://h71000.www7.hp.com/commercial/c/docs/5492profile_016.html |title=OpenVMS Format of Return Status Values |publisher=H71000.www7.hp.com |access-date=2012-07-09 |archive-url=https://web.archive.org/web/20120319171215/http://h71000.www7.hp.com/commercial/c/docs/5492profile_016.html |archive-date=2012-03-19 |url-status=dead}}</ref> <ref name="BD_syswait">{{man|bd|sys_wait.h|SUS}}</ref> <ref name="SH_waitid">{{man|sh|waitid|SUS}}</ref> <ref name="SH_wait">{{man|sh|wait|SUS}}</ref> <ref name="OpenGroup">{{cite web |url=http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_04_03_03 |title=2.4.3 Signal Actions |publisher=The Open Group |access-date=2019-02-08}}</ref> <ref name="ExitStatus">{{cite web |url=http://www.faqs.org/docs/abs/HTML/exit-status.html |title=Chapter 6. Exit and Exit Status |publisher=Faqs.org |access-date=2012-07-09}}</ref> <ref name="FreeBSD">{{man|3|sysexits|FreeBSD|preferable exit codes for programs}}</ref> <ref name="sysexits">Google search for «"sysexits.h" site:github.com» reports «About 3,540 results»; retrieved 2013-02-21.</ref> <ref name="SpecialMeanings">{{cite web |url=http://tldp.org/LDP/abs/html/exitcodes.html |title=Exit Codes with Special Meanings}}</ref> <ref name="ExitProcess">{{cite web |url=https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx |title=ExitProcess function |access-date=2016-12-16}}</ref> <ref name="GetExitCodeProcess">{{cite web |url=https://docs.microsoft.com/ja-jp/windows/win32/api/processthreadsapi/nf-processthreadsapi-getexitcodeprocess |title=GetExitCodeProcess function |access-date=2022-04-22}}</ref> <ref name="ExitCodesBig">{{cite web |url=https://stackoverflow.com/questions/179565/exitcodes-bigger-than-255-possible |title=ExitCodes bigger than 255, possible? |access-date=2009-09-28}}</ref> <ref name="Woude_2007">{{cite web |url=http://www.robvanderwoude.com/errorlevel.php |title=Errorlevels |publisher=Rob van der Woude's Scripting Pages |access-date=2007-08-26}}</ref>

</references>

{{DEFAULTSORT:Exit Status}} Category:Process (computing)