Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Exit status
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{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 [[computer process|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 [[computer process|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)|''exit'']] [[system call]]. This system call facilitates passing the exit status code back to the parent, which can retrieve this value using the [[wait (operating system)|''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 (computing)|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 [[Or (logic)|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: * OK 0 * WARN 5 * ERROR 10 * FAILURE 20 ===Shell and scripts=== [[Shell script]]s 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 N, a shell sets the variable $? to a value greater than 128. Most shells use 128+N, while ksh93 uses 256+N. If a command is not found, the shell should return a status of 127. If a command is found but is not executable, the return status should be 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)|C]] programming language allows programs exiting or returning from the [[main function]] to signal success or failure by returning an integer, or returning the [[Macro (computer science)|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|executable program]] or [[subroutine]]. Errorlevels typically range from 0 to 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 DOS 6.0]] and higher support 16-bit error codes at least in [[CONFIG.SYS]].<ref name="Paul_1997_NWDOSTIP"/> With [[4DOS]] and DR-DOS [[COMMAND.COM]], exit codes (in batchjobs) can be set by [[EXIT (DOS command)|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 CONFIG.SYS) through [[ERROR (CONFIG.SYS directive)|ERROR=''n'']]<!-- and a number of other more specialized directives -->.<ref name="Paul_1997_NWDOSTIP"/> Exit statuses are often captured by [[batch file|batch programs]] through [[IF ERRORLEVEL (DOS command)|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. COMMAND.COM under [[DR-DOS 7.02]] and higher supports a similar [[pseudo-environment variable]] %ERRORLVL% as well as [[%ERRORLEVEL%]].<!-- MS-DOS and PC DOS do not, only Windows does! --> In CONFIG.SYS, DR DOS 6.0 and higher supports [[ONERROR (CONFIG.SYS directive)|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 ''exits'' function, and [[Entry point#C and C++|function main]] is [[Void type|type void]]. ===POSIX=== In [[Unix]] and other [[POSIX|POSIX-compatible systems]], the parent process can retrieve the exit status of a child process using the <code>[[Wait (system call)|wait()]]</code> family of system calls defined in [[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 (computing)|signal]]), [[Single UNIX Specification|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 [[sysexits.h]].<ref name="FreeBSD"/> These historically derive from [[sendmail]] and other [[message transfer agent]]s, 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"/> ===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 [[Command Prompt (Windows)|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== {{reflist|refs= <ref name="Paul_1997_NWDOSTIP">{{cite book |title=NWDOS-TIPs — 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 — 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> }} {{DEFAULTSORT:Exit Status}} [[Category:Process (computing)]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Redirect
(
edit
)
Template:Redirect2
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)
Template:Use list-defined references
(
edit
)