<s>
The	O
exit	B-Operating_System
status	I-Operating_System
of	O
a	O
process	B-Operating_System
in	O
computer	B-General_Concept
programming	I-General_Concept
is	O
a	O
small	O
number	O
passed	O
from	O
a	O
child	B-Operating_System
process	I-Operating_System
(	O
or	O
callee	O
)	O
to	O
a	O
parent	B-Operating_System
process	I-Operating_System
(	O
or	O
caller	O
)	O
when	O
it	O
has	O
finished	O
executing	O
a	O
specific	O
procedure	O
or	O
delegated	O
task	O
.	O
</s>
<s>
In	O
DOS	B-Device
,	O
this	O
may	O
be	O
referred	O
to	O
as	O
an	O
errorlevel	B-Operating_System
.	O
</s>
<s>
When	O
computer	O
programs	O
are	O
executed	O
,	O
the	O
operating	B-General_Concept
system	I-General_Concept
creates	O
an	O
abstract	O
entity	O
called	O
a	O
process	B-Operating_System
in	O
which	O
the	O
book-keeping	O
for	O
that	O
program	O
is	O
maintained	O
.	O
</s>
<s>
In	O
multitasking	O
operating	B-General_Concept
systems	I-General_Concept
such	O
as	O
Unix	B-Application
or	O
Linux	B-Application
,	O
new	O
processes	O
can	O
be	O
created	O
by	O
active	O
processes	O
.	O
</s>
<s>
The	O
process	B-Operating_System
that	O
spawns	O
another	O
is	O
called	O
a	O
parent	B-Operating_System
process	I-Operating_System
,	O
while	O
those	O
created	O
are	O
child	O
processes	O
.	O
</s>
<s>
Child	O
processes	O
run	O
concurrently	O
with	O
the	O
parent	B-Operating_System
process	I-Operating_System
.	O
</s>
<s>
The	O
technique	O
of	O
spawning	O
child	O
processes	O
is	O
used	O
to	O
delegate	O
some	O
work	O
to	O
a	O
child	B-Operating_System
process	I-Operating_System
when	O
there	O
is	O
no	O
reason	O
to	O
stop	O
the	O
execution	O
of	O
the	O
parent	O
.	O
</s>
<s>
When	O
the	O
child	O
finishes	O
executing	O
,	O
it	O
exits	O
by	O
calling	O
the	O
exit	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
This	O
system	B-Operating_System
call	I-Operating_System
facilitates	O
passing	O
the	O
exit	B-Operating_System
status	I-Operating_System
code	O
back	O
to	O
the	O
parent	O
,	O
which	O
can	O
retrieve	O
this	O
value	O
using	O
the	O
wait	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
The	O
parent	O
and	O
the	O
child	O
can	O
have	O
an	O
understanding	O
about	O
the	O
meaning	O
of	O
the	O
exit	B-Operating_System
statuses	I-Operating_System
.	O
</s>
<s>
For	O
example	O
,	O
it	O
is	O
common	O
programming	O
practice	O
for	O
a	O
child	B-Operating_System
process	I-Operating_System
to	O
return	O
(	O
exit	O
with	O
)	O
zero	O
to	O
the	O
parent	O
signifying	O
success	O
.	O
</s>
<s>
Apart	O
from	O
this	O
return	B-Language
value	I-Language
from	O
the	O
child	O
,	O
other	O
information	O
like	O
how	O
the	O
process	B-Operating_System
exited	O
,	O
either	O
normally	O
or	O
by	O
a	O
signal	B-Operating_System
may	O
also	O
be	O
available	O
to	O
the	O
parent	B-Operating_System
process	I-Operating_System
.	O
</s>
<s>
Alternatively	O
,	O
each	O
bit	O
may	O
indicate	O
a	O
different	O
condition	O
,	O
with	O
these	O
being	O
evaluated	O
by	O
the	O
or	O
operator	O
together	O
to	O
give	O
the	O
final	O
value	O
;	O
for	O
example	O
,	O
fsck	B-Device
does	O
this	O
.	O
</s>
<s>
In	O
AmigaOS	B-Application
,	O
MorphOS	B-Operating_System
and	O
AROS	B-Application
,	O
four	O
levels	O
are	O
defined	O
:	O
</s>
<s>
Shell	B-Language
scripts	I-Language
typically	O
execute	O
commands	O
and	O
capture	O
their	O
exit	B-Operating_System
statuses	I-Operating_System
.	O
</s>
<s>
For	O
the	O
shell	O
’s	O
purposes	O
,	O
a	O
command	O
which	O
exits	O
with	O
a	O
zero	O
exit	B-Operating_System
status	I-Operating_System
has	O
succeeded	O
.	O
</s>
<s>
A	O
nonzero	O
exit	B-Operating_System
status	I-Operating_System
indicates	O
failure	O
.	O
</s>
<s>
When	O
a	O
command	O
is	O
terminated	O
by	O
a	O
signal	B-Operating_System
whose	O
number	O
is	O
N	O
,	O
a	O
shell	O
sets	O
the	O
variable	O
$	O
?	O
</s>
<s>
If	O
a	O
command	O
is	O
found	O
but	O
is	O
not	O
executable	B-Application
,	O
the	O
return	O
status	O
should	O
be	O
126	O
.	O
</s>
<s>
If	O
a	O
command	O
fails	O
because	O
of	O
an	O
error	O
during	O
expansion	O
or	O
redirection	O
,	O
the	O
exit	B-Operating_System
status	I-Operating_System
is	O
greater	O
than	O
zero	O
.	O
</s>
<s>
The	O
C	B-Language
programming	I-Language
language	I-Language
allows	O
programs	O
exiting	O
or	O
returning	O
from	O
the	O
main	B-Language
function	I-Language
to	O
signal	B-Operating_System
success	O
or	O
failure	O
by	O
returning	O
an	O
integer	O
,	O
or	O
returning	O
the	O
macros	O
EXIT_SUCCESS	O
and	O
EXIT_FAILURE	O
.	O
</s>
<s>
On	O
Unix-like	O
systems	O
these	O
are	O
equal	O
to	O
0	O
and	O
1	O
respectively	O
.	O
</s>
<s>
A	O
C	B-Language
program	I-Language
may	O
also	O
use	O
the	O
exit( )	O
function	O
specifying	O
the	O
integer	O
status	O
or	O
exit	O
macro	O
as	O
the	O
first	O
parameter	O
.	O
</s>
<s>
The	O
return	B-Language
value	I-Language
from	O
main	O
is	O
passed	O
to	O
the	O
exit	O
function	O
,	O
which	O
for	O
values	O
zero	O
,	O
EXIT_SUCCESS	O
or	O
EXIT_FAILURE	O
may	O
translate	O
it	O
to	O
“	O
an	O
implementation	O
defined	O
form	O
”	O
of	O
successful	O
termination	O
or	O
unsuccessful	O
termination	O
.	O
</s>
<s>
Apart	O
from	O
zero	O
and	O
the	O
macros	O
EXIT_SUCCESS	O
and	O
EXIT_FAILURE	O
,	O
the	O
C	B-Language
standard	O
does	O
not	O
define	O
the	O
meaning	O
of	O
return	B-Application
codes	I-Application
.	O
</s>
<s>
Rules	O
for	O
the	O
use	O
of	O
return	B-Application
codes	I-Application
vary	O
on	O
different	O
platforms	O
(	O
see	O
the	O
platform-specific	O
sections	O
)	O
.	O
</s>
<s>
In	O
DOS	B-Device
terminology	O
,	O
an	O
errorlevel	B-Operating_System
is	O
an	O
integer	O
exit	B-Operating_System
code	I-Operating_System
returned	O
by	O
an	O
executable	B-Application
program	I-Application
or	O
subroutine	O
.	O
</s>
<s>
Errorlevels	B-Operating_System
typically	O
range	O
from	O
0	O
to	O
255	O
.	O
</s>
<s>
In	O
DOS	B-Device
there	O
are	O
only	O
256	O
error	B-Application
codes	I-Application
available	O
,	O
but	O
DR	O
DOS	B-Device
6.0	O
and	O
higher	O
support	O
16-bit	O
error	B-Application
codes	I-Application
at	O
least	O
in	O
CONFIG.SYS	B-Device
.	O
</s>
<s>
With	O
4DOS	B-Application
and	O
DR-DOS	O
COMMAND.COM	B-Operating_System
,	O
exit	B-Operating_System
codes	I-Operating_System
(	O
in	O
batchjobs	O
)	O
can	O
be	O
set	O
by	O
EXIT	O
n	O
and	O
(	O
in	O
CONFIG.SYS	B-Device
)	O
through	O
ERROR	O
=	O
n	O
.	O
</s>
<s>
Exit	B-Operating_System
statuses	I-Operating_System
are	O
often	O
captured	O
by	O
batch	O
programs	O
through	O
IF	O
ERRORLEVEL	B-Operating_System
commands	O
.	O
</s>
<s>
Multiuser	B-Operating_System
DOS	I-Operating_System
supports	O
a	O
reserved	O
environment	O
variable	O
%ERRORLVL%	O
which	O
gets	O
automatically	O
updated	O
on	O
return	O
from	O
applications	O
.	O
</s>
<s>
COMMAND.COM	B-Operating_System
under	O
DR-DOS	O
7.02	O
and	O
higher	O
supports	O
a	O
similar	O
pseudo-environment	O
variable	O
%ERRORLVL%	O
as	O
well	O
as	O
%ERRORLEVEL%	O
.	O
</s>
<s>
In	O
CONFIG.SYS	B-Device
,	O
DRDOS	O
6.0	O
and	O
higher	O
supports	O
ONERROR	B-Device
to	O
test	O
the	O
load	O
status	O
and	O
return	B-Application
code	I-Application
of	O
device	O
drivers	O
and	O
the	O
exit	B-Operating_System
code	I-Operating_System
of	O
programs	O
.	O
</s>
<s>
This	O
will	O
terminate	B-Operating_System
the	O
currently	O
running	O
Java	O
Virtual	O
Machine	O
.	O
</s>
<s>
In	O
OpenVMS	B-Operating_System
,	O
success	O
is	O
indicated	O
by	O
odd	O
values	O
and	O
failure	O
by	O
even	O
values	O
.	O
</s>
<s>
In	O
Unix	B-Application
and	O
other	O
POSIX-compatible	O
systems	O
,	O
the	O
parent	B-Operating_System
process	I-Operating_System
can	O
retrieve	O
the	O
exit	B-Operating_System
status	I-Operating_System
of	O
a	O
child	B-Operating_System
process	I-Operating_System
using	O
the	O
wait( )	O
family	O
of	O
system	B-Operating_System
calls	I-Operating_System
defined	O
in	O
wait.h.	O
</s>
<s>
Of	O
these	O
,	O
the	O
waitid( )	O
call	O
retrieves	O
the	O
full	O
32-bit	O
exit	B-Operating_System
status	I-Operating_System
,	O
but	O
the	O
older	O
wait( )	O
and	O
waitpid( )	O
calls	O
retrieve	O
only	O
the	O
least	O
significant	O
8	O
bits	O
of	O
the	O
exit	B-Operating_System
status	I-Operating_System
.	O
</s>
<s>
The	O
wait( )	O
and	O
waitpid( )	O
interfaces	O
set	O
a	O
status	O
value	O
of	O
type	O
int	O
packed	O
as	O
a	O
bitfield	O
with	O
various	O
types	O
of	O
child	O
termination	O
information	O
.	O
</s>
<s>
If	O
the	O
child	O
terminated	O
by	O
exiting	O
(	O
as	O
determined	O
by	O
the	O
WIFEXITED( )	O
macro	O
;	O
the	O
usual	O
alternative	O
being	O
that	O
it	O
died	O
from	O
an	O
uncaught	O
signal	B-Operating_System
)	O
,	O
SUS	O
specifies	O
that	O
the	O
low-order	O
8	O
bits	O
of	O
the	O
exit	B-Operating_System
status	I-Operating_System
can	O
be	O
retrieved	O
from	O
the	O
status	O
value	O
using	O
the	O
WEXITSTATUS( )	O
macro	O
.	O
</s>
<s>
In	O
the	O
waitid( )	O
system	B-Operating_System
call	I-Operating_System
(	O
added	O
with	O
SUSv1	O
)	O
,	O
the	O
child	O
exit	B-Operating_System
status	I-Operating_System
and	O
other	O
information	O
are	O
no	O
longer	O
in	O
a	O
bitfield	O
but	O
in	O
the	O
structure	O
of	O
type	O
siginfo_t	O
.	O
</s>
<s>
Some	O
conventions	O
have	O
developed	O
as	O
to	O
the	O
relative	O
meanings	O
of	O
various	O
error	B-Application
codes	I-Application
;	O
for	O
example	O
GNU	O
recommend	O
that	O
codes	O
with	O
the	O
high	O
bit	O
set	O
be	O
reserved	O
for	O
serious	O
errors	O
.	O
</s>
<s>
These	O
historically	O
derive	O
from	O
sendmail	B-Application
and	O
other	O
message	B-Protocol
transfer	I-Protocol
agents	I-Protocol
,	O
but	O
they	O
have	O
since	O
found	O
use	O
in	O
many	O
other	O
programs	O
.	O
</s>
<s>
The	O
Advanced	O
Bash-Scripting	O
Guide	O
and	O
/usr/include/sysexits.h	O
have	O
some	O
information	O
on	O
the	O
meaning	O
of	O
non-0	O
exit	B-Operating_System
status	I-Operating_System
codes	O
.	O
</s>
<s>
Windows	B-Application
uses	O
32-bit	O
unsigned	O
integers	O
as	O
exit	B-Operating_System
codes	I-Operating_System
,	O
although	O
the	O
command	O
interpreter	O
treats	O
them	O
as	O
signed	O
.	O
</s>
<s>
Exit	B-Operating_System
codes	I-Operating_System
are	O
directly	O
referenced	O
,	O
for	O
example	O
,	O
by	O
the	O
command	O
line	O
interpreter	O
CMD.exe	B-Device
in	O
the	O
errorlevel	B-Operating_System
terminology	O
inherited	O
from	O
DOS	B-Device
.	O
</s>
<s>
.NET	B-Application
Framework	I-Application
processes	O
and	O
the	O
Windows	B-Application
PowerShell	I-Application
refer	O
to	O
it	O
as	O
the	O
ExitCode	B-Operating_System
property	O
of	O
the	O
Process	B-Operating_System
object	O
.	O
</s>
