]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/exec.3
ffix
[thirdparty/man-pages.git] / man3 / exec.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)exec.3 6.4 (Berkeley) 4/19/91
33.\"
34.\" Converted for Linux, Mon Nov 29 11:12:48 1993, faith@cs.unc.edu
35.\" Updated more for Linux, Tue Jul 15 11:54:18 1997, pacman@cqc.com
305a0578 36.\" Modified, 24 Jun 2004, Michael Kerrisk <mtk-manpages@gmx.net>
fea681da
MK
37.\" Added note on casting NULL
38.\"
69962544 39.TH EXEC 3 1993-11-29 "GNU" "Linux Programmer's Manual"
fea681da
MK
40.SH NAME
41execl, execlp, execle, execv, execvp \- execute a file
42.SH SYNOPSIS
43.B #include <unistd.h>
44.sp
45.B extern char **environ;
46.sp
47.BI "int execl(const char *" path ", const char *" arg ", ...);"
48.br
49.BI "int execlp(const char *" file ", const char *" arg ", ...);"
50.br
c7da82ff
MK
51.BI "int execle(const char *" path ", const char *" arg ,
52.br
53.BI " ..., char * const " envp "[]);"
fea681da
MK
54.br
55.BI "int execv(const char *" path ", char *const " argv "[]);"
56.br
57.BI "int execvp(const char *" file ", char *const " argv "[]);"
58.SH DESCRIPTION
59The
e1d6264d 60.BR exec ()
fea681da 61family of functions replaces the current process image with a new process
c13182ef
MK
62image.
63The functions described in this manual page are front-ends for the
fea681da
MK
64function
65.BR execve (2).
66(See the manual page for
fb186734 67.BR execve (2)
fea681da
MK
68for detailed information about the replacement of the current process.)
69.PP
70The initial argument for these functions is the pathname of a file which is
71to be executed.
72.PP
73The
74.I "const char *arg"
75and subsequent ellipses in the
e511ffb6
MK
76.BR execl (),
77.BR execlp (),
fea681da 78and
e511ffb6 79.BR execle ()
fea681da
MK
80functions can be thought of as
81.IR arg0 ,
82.IR arg1 ,
83\&...,
84.IR argn .
85Together they describe a list of one or more pointers to null-terminated
86strings that represent the argument list available to the executed program.
2c5f1089 87The first argument, by convention, should point to the filename associated
c13182ef
MK
88with the file being executed.
89The list of arguments
fea681da 90.I must
8478ee02 91be terminated by a NULL
fea681da
MK
92pointer, and, since these are variadic functions, this pointer must be cast
93.BR "(char *) NULL" .
94.PP
95The
e511ffb6 96.BR execv ()
fea681da 97and
e511ffb6 98.BR execvp ()
fea681da 99functions provide an array of pointers to null-terminated strings that
c13182ef
MK
100represent the argument list available to the new program.
101The first argument, by convention, should point to the filename
102associated with the file being executed.
103The array of pointers
fea681da 104.I must
8478ee02 105be terminated by a NULL pointer.
fea681da
MK
106.PP
107The
e511ffb6 108.BR execle ()
fea681da 109function also specifies the environment of the executed process by following
8478ee02 110the NULL
fea681da 111pointer that terminates the list of arguments in the parameter list or the
c13182ef
MK
112pointer to the argv array with an additional parameter.
113This additional
fea681da
MK
114parameter is an array of pointers to null-terminated strings and
115.I must
c13182ef 116be terminated by a NULL pointer.
8478ee02 117The other functions take the environment for the new process
fea681da
MK
118image from the external variable
119.I environ
120in the current process.
acffc0bc 121.SS Special semantics for execlp() and execvp()
fea681da
MK
122.PP
123The functions
e511ffb6 124.BR execlp ()
fea681da 125and
e511ffb6 126.BR execvp ()
fea681da 127will duplicate the actions of the shell in searching for an executable file
c13182ef
MK
128if the specified filename does not contain a slash (/) character.
129The search path is the path specified in the environment by the
fea681da 130.B PATH
c13182ef
MK
131variable.
132If this variable isn't specified, the default path
133``:/bin:/usr/bin'' is used.
134In addition, certain
fea681da
MK
135errors are treated specially.
136.PP
137If permission is denied for a file (the attempted
a51a49df 138.BR execve (2)
fea681da
MK
139returned
140.BR EACCES ),
c13182ef
MK
141these functions will continue searching the rest of the search path.
142If no other file is found, however,
143they will return with the global variable
fea681da
MK
144.I errno
145set to
146.BR EACCES .
147.PP
148If the header of a file isn't recognized (the attempted
a51a49df 149.BR execve (2)
fea681da
MK
150returned
151.BR ENOEXEC ),
988db661 152these functions will execute the shell
acffc0bc
MK
153.RI ( /bin/sh )
154with the path of the file as its first argument.
c13182ef 155(If this attempt fails, no further searching is done.)
fea681da
MK
156.SH "RETURN VALUE"
157If any of the
e1d6264d 158.BR exec ()
c13182ef
MK
159functions returns, an error will have occurred.
160The return value is \-1,
fea681da
MK
161and the global variable
162.I errno
163will be set to indicate the error.
fea681da
MK
164.SH ERRORS
165All of these functions may fail and set
166.I errno
167for any of the errors specified for the library function
168.BR execve (2).
2b2581ee
MK
169.SH "CONFORMING TO"
170POSIX.1-2001.
8af1ba10 171.SH NOTES
fea681da
MK
172On some other systems the default path (used when the environment
173does not contain the variable \fBPATH\fR) has the current working
174directory listed after
175.I /bin
176and
177.IR /usr/bin ,
c13182ef
MK
178as an anti-Trojan-horse measure.
179Linux uses here the
fea681da
MK
180traditional "current directory first" default path.
181.PP
182The behavior of
e511ffb6 183.BR execlp ()
fea681da 184and
e511ffb6 185.BR execvp ()
fea681da
MK
186when errors occur while attempting to execute the file is historic
187practice, but has not traditionally been documented and is not specified by
c13182ef
MK
188the POSIX standard.
189BSD (and possibly other systems) do an automatic
2f0af33b
MK
190sleep and retry if
191.B ETXTBSY
192is encountered.
c13182ef 193Linux treats it as a hard
fea681da
MK
194error and returns immediately.
195.PP
196Traditionally, the functions
e511ffb6 197.BR execlp ()
fea681da 198and
e511ffb6 199.BR execvp ()
fea681da
MK
200ignored all errors except for the ones described above and
201.B ENOMEM
202and
203.BR E2BIG ,
c13182ef
MK
204upon which they returned.
205They now return if any error other than the ones
fea681da 206described above occurs.
e37e3282
MK
207.SH "SEE ALSO"
208.BR sh (1),
209.BR execve (2),
210.BR fork (2),
211.BR ptrace (2),
212.BR fexecve (3),
213.BR environ (7)