Exit status
From Wikipedia, the free encyclopedia
The exit status of a process in computer programming is a small number passed from a child process to a parent process when it is done executing a specific task delegated. On DOS, this may be referred to as an errorlevel.
When software programs are run or executed, the operating system creates an abstract entity called a computer process in which all the book-keeping for that program is done. In multitasking operating systems such as UNIX or Linux, 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 the main function; this has the same effect.)
Contents |
[edit] 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 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[1].
[edit] C
The C programming language requires only that programs exiting or returning from the main function be able to signal success or failure, using the macros EXIT_SUCCESS
and EXIT_FAILURE
; on Unix-like systems these evaluate to 0 and 1 respectively.[2] A fully portable C program cannot depend on any other value being available.
[edit] 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." [3] (int status
is the errorlevel.)
[edit] Unix
On Unix, the wait
system call sets a status value of type int packed as a bitfield 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;[4] this can be retrieved using the WEXITSTATUS macro in wait.h.[5] 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.[6] 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,[2] and FreeBSD have documented an extensive set of preferred interpretations.[7]
[edit] DOS
In DOS terminology, an errorlevel is an integer exit code returned by an executable program or subroutine. Errorlevels typically range from 0 to 255. In DOS 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).[8]
[edit] References
- ^ Errorlevels. Rob van der Woude's Scripting Pages. Retrieved on 2007-08-26.
- ^ a b The GNU C Library Reference Manual 25.6.2: Exit Status
- ^ Java 1.6.0 API. Sun. Retrieved on 2008-05-06.
- ^ – System Interfaces Reference, The Single UNIX® Specification, Issue 6 from The Open Group
- ^ – Base Definitions Reference, The Single UNIX® Specification, Issue 6 from The Open Group
- ^ http://www.faqs.org/docs/abs/HTML/exit-status.html
- ^ : preferable exit codes for programs – FreeBSD Library Functions Manual
- ^ build reported as successful on win xp even when maven 1 build fails. Codehaus. Retrieved on 2007-08-26.