<s>
In	O
computing	O
,	O
exec	B-Operating_System
is	O
a	O
functionality	O
of	O
an	O
operating	B-General_Concept
system	I-General_Concept
that	O
runs	O
an	O
executable	B-Application
file	I-Application
in	O
the	O
context	O
of	O
an	O
already	O
existing	O
process	B-Operating_System
,	O
replacing	O
the	O
previous	O
executable	B-Application
.	O
</s>
<s>
It	O
is	O
especially	O
important	O
in	O
Unix-like	B-Operating_System
systems	I-Operating_System
,	O
although	O
it	O
exists	O
elsewhere	O
.	O
</s>
<s>
As	O
no	O
new	O
process	B-Operating_System
is	O
created	O
,	O
the	O
process	B-Operating_System
identifier	I-Operating_System
(	O
PID	O
)	O
does	O
not	O
change	O
,	O
but	O
the	O
machine	B-Language
code	I-Language
,	O
data	B-General_Concept
,	O
heap	O
,	O
and	O
stack	B-General_Concept
of	O
the	O
process	B-Operating_System
are	O
replaced	O
by	O
those	O
of	O
the	O
new	O
program	O
.	O
</s>
<s>
The	O
exec	B-Operating_System
call	O
is	O
available	O
for	O
many	O
programming	O
languages	O
including	O
compilable	B-Language
languages	O
and	O
some	O
scripting	B-Language
languages	I-Language
.	O
</s>
<s>
In	O
OS	B-Operating_System
command	I-Operating_System
interpreters	I-Operating_System
,	O
the	O
built-in	O
command	O
replaces	O
the	O
shell	O
process	B-Operating_System
with	O
the	O
specified	O
program	O
.	O
</s>
<s>
Interfaces	O
to	O
exec	B-Operating_System
and	O
its	O
implementations	O
vary	O
.	O
</s>
<s>
Depending	O
on	O
programming	O
language	O
it	O
may	O
be	O
accessible	O
via	O
one	O
or	O
more	O
functions	O
,	O
and	O
depending	O
on	O
operating	B-General_Concept
system	I-General_Concept
it	O
may	O
be	O
represented	O
with	O
one	O
or	O
more	O
actual	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
For	O
this	O
reason	O
exec	B-Operating_System
is	O
sometimes	O
described	O
as	O
a	O
collection	O
of	O
functions	O
.	O
</s>
<s>
Standard	O
names	O
of	O
such	O
functions	O
in	O
C	B-Language
are	O
,	O
,	O
,	O
,	O
,	O
and	O
(	O
see	O
below	O
)	O
,	O
but	O
not	O
"	O
exec	B-Operating_System
"	O
itself	O
.	O
</s>
<s>
The	O
Linux	B-Operating_System
kernel	I-Operating_System
has	O
one	O
corresponding	O
system	B-Operating_System
call	I-Operating_System
named	O
"	O
execve	B-Operating_System
"	O
,	O
whereas	O
all	O
aforementioned	O
functions	O
are	O
user-space	B-Library
wrappers	I-Library
around	O
it	O
.	O
</s>
<s>
Higher-level	B-Language
languages	I-Language
usually	O
provide	O
one	O
call	O
named	O
.	O
</s>
<s>
The	O
POSIX	O
standard	O
declares	O
exec	B-Operating_System
functions	O
in	O
the	O
header	O
file	O
,	O
in	O
the	O
C	B-Language
language	I-Language
.	O
</s>
<s>
The	O
same	O
functions	O
are	O
declared	O
in	O
for	O
DOS	B-Device
(	O
see	O
below	O
)	O
,	O
OS/2	O
,	O
and	O
Microsoft	O
Windows	O
.	O
</s>
<s>
int	O
execl( char	O
const	O
*	O
path	O
,	O
char	O
const	O
*	O
arg0	O
,	O
...	O
)	O
;	O
</s>
<s>
int	O
execle( char	O
const	O
*	O
path	O
,	O
char	O
const	O
*	O
arg0	O
,	O
...	O
,	O
char	O
const	O
*envp[]	O
)	O
;	O
</s>
<s>
int	O
execv( char	O
const	O
*	O
path	O
,	O
char	O
const	O
*argv[]	O
)	O
;	O
</s>
<s>
int	O
execve( char	O
const	O
*	O
path	O
,	O
char	O
const	O
*argv[],	O
char	O
const	O
*envp[]	O
)	O
;	O
</s>
<s>
The	O
base	O
of	O
each	O
is	O
exec	B-Operating_System
(	O
execute	O
)	O
,	O
followed	O
by	O
one	O
or	O
more	O
letters	O
:	O
</s>
<s>
e	O
–	O
An	O
array	O
of	O
pointers	O
to	O
environment	O
variables	O
is	O
explicitly	O
passed	O
to	O
the	O
new	O
process	B-Operating_System
image	O
.	O
</s>
<s>
p	O
–	O
Uses	O
the	O
PATH	B-Application
environment	I-Application
variable	I-Application
to	O
find	O
the	O
file	O
named	O
in	O
the	O
file	O
argument	O
to	O
be	O
executed	O
.	O
</s>
<s>
The	O
argument	O
specifies	O
the	O
path	O
name	O
of	O
the	O
file	O
to	O
execute	O
as	O
the	O
new	O
process	B-Operating_System
image	O
.	O
</s>
<s>
Arguments	O
beginning	O
at	O
arg0	O
are	O
pointers	O
to	O
arguments	O
to	O
be	O
passed	O
to	O
the	O
new	O
process	B-Operating_System
image	O
.	O
</s>
<s>
The	O
first	O
argument	O
arg0	O
should	O
be	O
the	O
name	O
of	O
the	O
executable	B-Application
file	I-Application
.	O
</s>
<s>
Some	O
programs	O
may	O
incorrectly	O
rely	O
on	O
this	O
argument	O
providing	O
the	O
location	O
of	O
the	O
executable	B-Application
,	O
but	O
there	O
is	O
no	O
guarantee	O
of	O
this	O
nor	O
is	O
it	O
standardized	O
across	O
platforms	O
.	O
</s>
<s>
The	O
exec	B-Operating_System
calls	O
named	O
ending	O
with	O
an	O
e	O
alter	O
the	O
environment	O
for	O
the	O
new	O
process	B-Operating_System
image	O
by	O
passing	O
a	O
list	O
of	O
environment	O
settings	O
through	O
the	O
envp	O
argument	O
.	O
</s>
<s>
This	O
argument	O
is	O
an	O
array	O
of	O
character	O
pointers	O
;	O
each	O
element	O
(	O
except	O
for	O
the	O
final	O
element	O
)	O
points	O
to	O
a	O
null-terminated	B-Data_Structure
string	I-Data_Structure
defining	O
an	O
environment	O
variable	O
.	O
</s>
<s>
Each	O
null-terminated	B-Data_Structure
string	I-Data_Structure
has	O
the	O
form	O
:	O
</s>
<s>
In	O
the	O
,	O
,	O
,	O
and	O
calls	O
,	O
the	O
new	O
process	B-Operating_System
image	O
inherits	O
the	O
current	O
environment	O
variables	O
.	O
</s>
<s>
A	O
file	B-Application
descriptor	I-Application
open	O
when	O
an	O
exec	B-Operating_System
call	O
is	O
made	O
remains	O
open	O
in	O
the	O
new	O
process	B-Operating_System
image	O
,	O
unless	O
was	O
ed	O
with	O
FD_CLOEXEC	O
or	O
opened	O
with	O
O_CLOEXEC	O
(	O
the	O
latter	O
was	O
introduced	O
in	O
POSIX.1-2001	O
)	O
.	O
</s>
<s>
This	O
aspect	O
is	O
used	O
to	O
specify	O
the	O
standard	B-Operating_System
streams	I-Operating_System
(	O
stdin	O
,	O
stdout	O
and	O
stderr	O
)	O
of	O
the	O
new	O
program	O
.	O
</s>
<s>
A	O
successful	O
overlay	O
destroys	O
the	O
previous	O
memory	B-General_Concept
address	I-General_Concept
space	O
of	O
the	O
process	B-Operating_System
,	O
and	O
all	O
its	O
memory	O
areas	O
,	O
that	O
were	O
not	O
shared	B-Operating_System
,	O
are	O
reclaimed	O
by	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
Consequently	O
,	O
all	O
its	O
data	B-General_Concept
that	O
were	O
not	O
passed	O
to	O
the	O
new	O
program	O
,	O
or	O
otherwise	O
saved	O
,	O
become	O
lost	O
.	O
</s>
<s>
A	O
successful	O
exec	B-Operating_System
replaces	O
the	O
current	O
process	B-Operating_System
image	O
,	O
so	O
it	O
cannot	O
return	O
anything	O
to	O
the	O
program	O
that	O
made	O
the	O
call	O
.	O
</s>
<s>
Processes	O
do	O
have	O
an	O
exit	B-Operating_System
status	I-Operating_System
,	O
but	O
that	O
value	O
is	O
collected	O
by	O
the	O
parent	B-Operating_System
process	I-Operating_System
.	O
</s>
<s>
If	O
an	O
exec	B-Operating_System
function	O
does	O
return	O
to	O
the	O
calling	O
program	O
,	O
an	O
error	O
occurs	O
,	O
the	O
return	O
value	O
is	O
−1	O
,	O
and	O
errno	B-Error_Name
is	O
set	O
to	O
one	O
of	O
the	O
following	O
values	O
:	O
</s>
<s>
ENOMEM	O
Not	O
enough	O
memory	O
is	O
available	O
to	O
execute	O
the	O
new	O
process	B-Operating_System
image	O
.	O
</s>
<s>
DOS	B-Device
is	O
not	O
a	O
multitasking	B-Operating_System
operating	I-Operating_System
system	I-Operating_System
,	O
but	O
replacing	O
the	O
previous	O
executable	B-Application
image	O
has	O
a	O
great	O
merit	O
there	O
due	O
to	O
harsh	O
primary	O
memory	O
limitations	O
and	O
lack	O
of	O
virtual	B-Architecture
memory	I-Architecture
.	O
</s>
<s>
The	O
same	O
API	O
is	O
used	O
for	O
overlaying	O
programs	O
in	O
DOS	B-Device
and	O
it	O
has	O
effects	O
similar	O
to	O
ones	O
on	O
POSIX	O
systems	O
.	O
</s>
<s>
MS-DOS	B-Application
exec	B-Operating_System
functions	O
always	O
load	O
the	O
new	O
program	O
into	O
memory	O
as	O
if	O
the	O
"	O
maximum	O
allocation	O
"	O
in	O
the	O
program	O
's	O
executable	B-Application
file	I-Application
header	O
is	O
set	O
to	O
default	O
value	O
0xFFFF	O
.	O
</s>
<s>
However	O
,	O
if	O
this	O
is	O
done	O
and	O
the	O
program	O
is	O
invoked	O
with	O
one	O
of	O
the	O
exec	B-Operating_System
functions	O
,	O
the	O
program	O
might	O
behave	O
differently	O
from	O
a	O
program	O
invoked	O
directly	O
from	O
the	O
operating-system	O
command	O
line	O
or	O
with	O
one	O
of	O
the	O
spawn	B-Language
functions	O
(	O
see	O
below	O
)	O
.	O
</s>
<s>
Many	O
Unix	B-Application
shells	I-Application
also	O
offer	O
a	O
builtin	O
command	O
that	O
replaces	O
the	O
shell	O
process	B-Operating_System
with	O
the	O
specified	O
program	O
.	O
</s>
<s>
Wrapper	O
scripts	O
often	O
use	O
this	O
command	O
to	O
run	O
a	O
program	O
(	O
either	O
directly	O
or	O
through	O
an	O
interpreter	B-Application
or	O
virtual	B-Architecture
machine	I-Architecture
)	O
after	O
setting	O
environment	O
variables	O
or	O
other	O
configuration	O
.	O
</s>
<s>
By	O
using	O
exec	B-Operating_System
,	O
the	O
resources	O
used	O
by	O
the	O
shell	O
program	O
do	O
not	O
need	O
to	O
stay	O
in	O
use	O
after	O
the	O
program	O
is	O
started	O
.	O
</s>
<s>
The	O
command	O
can	O
also	O
perform	O
a	O
redirection	B-Device
.	O
</s>
<s>
In	O
some	O
shells	O
it	O
is	O
even	O
possible	O
to	O
use	O
the	O
command	O
for	O
redirection	B-Device
only	O
,	O
without	O
making	O
an	O
actual	O
overlay	O
.	O
</s>
<s>
The	O
traditional	B-Application
Unix	I-Application
system	O
does	O
not	O
have	O
the	O
functionality	O
to	O
create	O
a	O
new	O
process	B-Operating_System
running	O
a	O
new	O
executable	B-Application
program	I-Application
in	O
one	O
step	O
,	O
which	O
explains	O
the	O
importance	O
of	O
exec	B-Operating_System
for	O
Unix	B-Application
programming	O
.	O
</s>
<s>
Other	O
systems	O
may	O
use	O
spawn	B-Language
as	O
the	O
main	O
tool	O
for	O
running	O
executables	B-Application
.	O
</s>
<s>
Its	O
result	O
is	O
equivalent	O
to	O
the	O
fork	B-Operating_System
–	I-Operating_System
exec	I-Operating_System
sequence	O
of	O
Unix-like	B-Operating_System
systems	I-Operating_System
.	O
</s>
<s>
OS/360	B-Application
and	I-Application
successors	I-Application
include	O
a	O
system	B-Operating_System
call	I-Operating_System
XCTL	O
(	O
transfer	O
control	O
)	O
that	O
performs	O
a	O
similar	O
function	O
to	O
exec	B-Operating_System
.	O
</s>
