]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/exec.3
getauxval.3: wfix
[thirdparty/man-pages.git] / man3 / exec.3
1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" %%%LICENSE_END
33 .\"
34 .\" @(#)exec.3 6.4 (Berkeley) 4/19/91
35 .\"
36 .\" Converted for Linux, Mon Nov 29 11:12:48 1993, faith@cs.unc.edu
37 .\" Updated more for Linux, Tue Jul 15 11:54:18 1997, pacman@cqc.com
38 .\" Modified, 24 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
39 .\" Added note on casting NULL
40 .\"
41 .TH EXEC 3 2015-04-19 "GNU" "Linux Programmer's Manual"
42 .SH NAME
43 execl, execlp, execle, execv, execvp, execvpe \- execute a file
44 .SH SYNOPSIS
45 .B #include <unistd.h>
46 .sp
47 .B extern char **environ;
48 .sp
49 .BI "int execl(const char *" path ", const char *" arg ", ..."
50 .br
51 .B " /* (char *) NULL */);"
52 .br
53 .BI "int execlp(const char *" file ", const char *" arg ", ..."
54 .br
55 .B " /* (char *) NULL */);"
56 .br
57 .BI "int execle(const char *" path ", const char *" arg ", ..."
58 .br
59 .BI " /*, (char *) NULL, char * const " envp "[] */);"
60 .br
61 .BI "int execv(const char *" path ", char *const " argv "[]);"
62 .br
63 .BI "int execvp(const char *" file ", char *const " argv "[]);"
64 .br
65 .BI "int execvpe(const char *" file ", char *const " argv "[],"
66 .br
67 .BI " char *const " envp "[]);"
68 .sp
69 .in -4n
70 Feature Test Macro Requirements for glibc (see
71 .BR feature_test_macros (7)):
72 .in
73 .sp
74 .BR execvpe ():
75 _GNU_SOURCE
76 .SH DESCRIPTION
77 The
78 .BR exec ()
79 family of functions replaces the current process image with a new process
80 image.
81 The functions described in this manual page are front-ends for
82 .BR execve (2).
83 (See the manual page for
84 .BR execve (2)
85 for further details about the replacement of the current process image.)
86 .PP
87 The initial argument for these functions is the name of a file that is
88 to be executed.
89 .PP
90 The
91 .I "const char\ *arg"
92 and subsequent ellipses in the
93 .BR execl (),
94 .BR execlp (),
95 and
96 .BR execle ()
97 functions can be thought of as
98 .IR arg0 ,
99 .IR arg1 ,
100 \&...,
101 .IR argn .
102 Together they describe a list of one or more pointers to null-terminated
103 strings that represent the argument list available to the executed program.
104 The first argument, by convention, should point to the filename associated
105 with the file being executed.
106 The list of arguments
107 .I must
108 be terminated by a null pointer,
109 and, since these are variadic functions, this pointer must be cast
110 .IR "(char\ *) NULL" .
111 .PP
112 The
113 .BR execv (),
114 .BR execvp (),
115 and
116 .BR execvpe ()
117 functions provide an array of pointers to null-terminated strings that
118 represent the argument list available to the new program.
119 The first argument, by convention, should point to the filename
120 associated with the file being executed.
121 The array of pointers
122 .I must
123 be terminated by a null pointer.
124 .PP
125 The
126 .BR execle ()
127 and
128 .BR execvpe ()
129 functions allow the caller to specify the environment of the
130 executed program via the argument
131 .IR envp .
132 The
133 .I envp
134 argument is an array of pointers to null-terminated strings and
135 .I must
136 be terminated by a null pointer.
137 The other functions take the environment for the new process
138 image from the external variable
139 .I environ
140 in the calling process.
141 .SS Special semantics for execlp() and execvp()
142 .PP
143 The
144 .BR execlp (),
145 .BR execvp (),
146 and
147 .BR execvpe ()
148 functions duplicate the actions of the shell in
149 searching for an executable file
150 if the specified filename does not contain a slash (/) character.
151 The file is sought in the colon-separated list of directory pathnames
152 specified in the
153 .B PATH
154 environment variable.
155 If this variable isn't defined, the path list defaults to
156 the current directory followed by the list of directories returned by
157 .IR confstr(_CS_PATH) .
158 (This
159 .BR confstr (3)
160 call typically returns the value "/bin:/usr/bin".)
161
162 If the specified filename includes a slash character, then
163 .B PATH
164 is ignored, and the file at the specified pathname is executed.
165
166 In addition, certain errors are treated specially.
167
168 If permission is denied for a file (the attempted
169 .BR execve (2)
170 failed with the error
171 .BR EACCES ),
172 these functions will continue searching the rest of the search path.
173 If no other file is found, however,
174 they will return with
175 .I errno
176 set to
177 .BR EACCES .
178
179 If the header of a file isn't recognized (the attempted
180 .BR execve (2)
181 failed with the error
182 .BR ENOEXEC ),
183 these functions will execute the shell
184 .RI ( /bin/sh )
185 with the path of the file as its first argument.
186 (If this attempt fails, no further searching is done.)
187 .SH RETURN VALUE
188 The
189 .BR exec ()
190 functions return only if an error has occurred.
191 The return value is \-1, and
192 .I errno
193 is set to indicate the error.
194 .SH ERRORS
195 All of these functions may fail and set
196 .I errno
197 for any of the errors specified for
198 .BR execve (2).
199 .SH VERSIONS
200 The
201 .BR execvpe ()
202 function first appeared in glibc 2.11.
203 .SH ATTRIBUTES
204 For an explanation of the terms used in this section, see
205 .BR attributes (7).
206 .TS
207 allbox;
208 lbw29 lb lb
209 l l l.
210 Interface Attribute Value
211 T{
212 .BR execl (),
213 .BR execle (),
214 .BR execv ()
215 T} Thread safety MT-Safe
216 T{
217 .BR execlp (),
218 .BR execvp (),
219 .BR execvpe ()
220 T} Thread safety MT-Safe env
221 .TE
222 .SH CONFORMING TO
223 POSIX.1-2001, POSIX.1-2008.
224
225 The
226 .BR execvpe ()
227 function is a GNU extension.
228 .SH NOTES
229 On some other systems, the default path (used when the environment
230 does not contain the variable \fBPATH\fR) has the current working
231 directory listed after
232 .I /bin
233 and
234 .IR /usr/bin ,
235 as an anti-Trojan-horse measure.
236 Linux uses here the
237 traditional "current directory first" default path.
238 .PP
239 The behavior of
240 .BR execlp ()
241 and
242 .BR execvp ()
243 when errors occur while attempting to execute the file is historic
244 practice, but has not traditionally been documented and is not specified by
245 the POSIX standard.
246 BSD (and possibly other systems) do an automatic
247 sleep and retry if
248 .B ETXTBSY
249 is encountered.
250 Linux treats it as a hard
251 error and returns immediately.
252 .PP
253 Traditionally, the functions
254 .BR execlp ()
255 and
256 .BR execvp ()
257 ignored all errors except for the ones described above and
258 .B ENOMEM
259 and
260 .BR E2BIG ,
261 upon which they returned.
262 They now return if any error other than the ones
263 described above occurs.
264 .SH SEE ALSO
265 .BR sh (1),
266 .BR execve (2),
267 .BR execveat (2),
268 .BR fork (2),
269 .BR ptrace (2),
270 .BR fexecve (3),
271 .BR environ (7)