- Exit status
The exit status of a process in
computer programming is an small number passed from achild process to aparent process when it is done executing a specific task delegated. OnDOS , this may be referred to as an errorlevel.When software programs are run or executed, the
operating system creates anabstract entity called acomputer process in which all the book-keeping for that program is done. In multitasking operating systems such as UNIX orLinux , new processes can be created by active processes. Such processes are parent processes while those created are child processes. It is common in programming for a parent process to delegate some work to a child process it creates while it may remain busy with something else. When the child is done executing, it will exit by calling the "exit"system call . This system call facilitates passing a small number back to the parent, which can retrieve this value using the "wait" system call. This is the exit status of the child. (A child may also exit by returning a value from themain function ; this has the same effect.)emantics
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 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 is also 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 [cite web|url=http://www.robvanderwoude.com/errorlevel.html|title=Errorlevels|publisher=Rob van der Woude's Scripting Pages|accessdate=2007-08-26] . Alternatively, each bit may indicate a different condition, which are then
xor ed together to give the final value; for example,fsck does this.C
The
C programming language requires only that programs exiting or returning from themain function be able to signal success or failure, using the macrosEXIT_SUCCESS
andEXIT_FAILURE
; on Unix-like systems these evaluate to 0 and 1 respectively. [http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html The GNU C Library Reference Manual 25.6.2: Exit Status] ] A fully portable C program cannot depend on any other value being available.Java
In Java, any method can call
System.exit(int status)
, unless a security manager does not permit this. 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." [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|accessdate=2008-05-06] (int status
is the errorlevel.)Unix
On
Unix , thewait
system call sets a "status" value of type int packed as abitfield with various types of child termination information. If the child terminated by exiting (as determined by the WIFEXITED macro; the usual alternative being that it died from an uncaught signal), SUS specifies that the lower 8 bits of the status value contain the exit status; [man|sh|wait|SUS] this can be retrieved using the WEXITSTATUS macro inwait.h . [man|bd|sys/wait.h|SUS] As such, on Unix exit statuses are restricted to values 0-255, the range of an unsigned 8-bit integer.Unix like systems typically use a convention of zero for success and non zero for error. [http://www.faqs.org/docs/abs/HTML/exit-status.html] 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, and FreeBSD have documented an extensive set of preferred interpretations. [man|3|sysexits|FreeBSD|preferable exit codes for programs]
DOS
In DOS terminology, an errorlevel is an
integer exitcode returned by an executable program orsubroutine . Errorlevels typically range from 0 to 255. InDOS there are only 255 error codes available.DOS started to support "
exit /B errorcode
". However, some programmers reported that it was not working properly on some systems (e.g.Windows XP Professional ). [cite web|url=http://jira.codehaus.org/browse/CONTINUUM-413|title=build reported as successful on win xp even when maven 1 build fails|publisher=Codehaus|accessdate=2007-08-26]References
ee also
*
Return statement
Wikimedia Foundation. 2010.