1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
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
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.
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
34 .\" @(#)exec.3 6.4 (Berkeley) 4/19/91
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
41 .TH EXEC 3 2019-03-06 "GNU" "Linux Programmer's Manual"
43 execl, execlp, execle, execv, execvp, execvpe \- execute a file
46 .B #include <unistd.h>
48 .B extern char **environ;
50 .BI "int execl(const char *" pathname ", const char *" arg ", ..."
51 .B " /* (char *) NULL */);"
52 .BI "int execlp(const char *" file ", const char *" arg ", ..."
53 .B " /* (char *) NULL */);"
54 .BI "int execle(const char *" pathname ", const char *" arg ", ..."
55 .BI " /*, (char *) NULL, char * const " envp "[] */);"
56 .BI "int execv(const char *" pathname ", char *const " argv "[]);"
57 .BI "int execvp(const char *" file ", char *const " argv "[]);"
58 .BI "int execvpe(const char *" file ", char *const " argv "[],"
59 .BI " char *const " envp "[]);"
63 Feature Test Macro Requirements for glibc (see
64 .BR feature_test_macros (7)):
72 family of functions replaces the current process image with a new process
74 The functions described in this manual page are front-ends for
76 (See the manual page for
78 for further details about the replacement of the current process image.)
80 The initial argument for these functions is the name of a file that is
85 and subsequent ellipses in the
90 functions can be thought of as
95 Together they describe a list of one or more pointers to null-terminated
96 strings that represent the argument list available to the executed program.
97 The first argument, by convention, should point to the filename associated
98 with the file being executed.
101 be terminated by a null pointer,
102 and, since these are variadic functions, this pointer must be cast
103 .IR "(char\ *) NULL" .
110 functions provide an array of pointers to null-terminated strings that
111 represent the argument list available to the new program.
112 The first argument, by convention, should point to the filename
113 associated with the file being executed.
114 The array of pointers
116 be terminated by a null pointer.
122 functions allow the caller to specify the environment of the
123 executed program via the argument
127 argument is an array of pointers to null-terminated strings and
129 be terminated by a null pointer.
130 The other functions take the environment for the new process
131 image from the external variable
133 in the calling process.
134 .SS Special semantics for execlp(), execvp(), and execvpe()
141 functions duplicate the actions of the shell in
142 searching for an executable file
143 if the specified filename does not contain a slash (/) character.
144 The file is sought in the colon-separated list of directory pathnames
147 environment variable.
148 If this variable isn't defined, the path list defaults to
149 a list that includes the directories returned by
150 .IR confstr(_CS_PATH)
151 (which typically returns the value "/bin:/usr/bin")
152 and possibly also the current working directory;
153 see NOTES for further details.
155 If the specified filename includes a slash character, then
157 is ignored, and the file at the specified pathname is executed.
159 In addition, certain errors are treated specially.
161 If permission is denied for a file (the attempted
163 failed with the error
165 these functions will continue searching the rest of the search path.
166 If no other file is found, however,
167 they will return with
172 If the header of a file isn't recognized (the attempted
174 failed with the error
176 these functions will execute the shell
178 with the path of the file as its first argument.
179 (If this attempt fails, no further searching is done.)
183 functions return only if an error has occurred.
184 The return value is \-1, and
186 is set to indicate the error.
188 All of these functions may fail and set
190 for any of the errors specified for
195 function first appeared in glibc 2.11.
197 For an explanation of the terms used in this section, see
203 Interface Attribute Value
208 T} Thread safety MT-Safe
213 T} Thread safety MT-Safe env
216 POSIX.1-2001, POSIX.1-2008.
220 function is a GNU extension.
222 The default search path (used when the environment
223 does not contain the variable \fBPATH\fR)
224 shows some variation across systems.
225 It generally includes
229 (in that order) and may also include the current working directory.
230 On some other systems, the current working is included after
234 as an anti-Trojan-horse measure.
235 The glibc implementation long followed the traditional default where
236 the current working directory is included at the start of the search path.
237 However, some code refactoring during the development of glibc 2.24
238 .\" glibc commit 1eb8930608705702d5746e5491bab4e4429fcb83
239 caused the current working directory to be dropped altogether
240 from the default search path.
241 This accidental behavior change is considered mildly beneficial,
242 and won't be reverted.
248 when errors occur while attempting to execute the file is historic
249 practice, but has not traditionally been documented and is not specified by
251 BSD (and possibly other systems) do an automatic
255 Linux treats it as a hard
256 error and returns immediately.
258 Traditionally, the functions
262 ignored all errors except for the ones described above and
266 upon which they returned.
267 They now return if any error other than the ones
268 described above occurs.
276 internally and were consequently not async-signal-safe,
277 in violation of the requirements of POSIX.1.
278 .\" https://sourceware.org/bugzilla/show_bug.cgi?id=19534
279 This was fixed in glibc 2.24.
281 .SS Architecture-specific details
282 On sparc and sparc64,
284 is provided as a system call by the kernel
285 (with the prototype shown above)
286 for compatibility with SunOS.
291 wrapper function on those architectures.