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 2015-04-19 "GNU" "Linux Programmer's Manual"
43 execl, execlp, execle, execv, execvp, execvpe \- execute a file
45 .B #include <unistd.h>
47 .B extern char **environ;
49 .BI "int execl(const char *" path ", const char *" arg ", ..."
51 .B " /* (char *) NULL */);"
53 .BI "int execlp(const char *" file ", const char *" arg ", ..."
55 .B " /* (char *) NULL */);"
57 .BI "int execle(const char *" path ", const char *" arg ", ..."
59 .BI " /*, (char *) NULL, char * const " envp "[] */);"
61 .BI "int execv(const char *" path ", char *const " argv "[]);"
63 .BI "int execvp(const char *" file ", char *const " argv "[]);"
65 .BI "int execvpe(const char *" file ", char *const " argv "[],"
67 .BI " char *const " envp "[]);"
70 Feature Test Macro Requirements for glibc (see
71 .BR feature_test_macros (7)):
79 family of functions replaces the current process image with a new process
81 The functions described in this manual page are front-ends for
83 (See the manual page for
85 for further details about the replacement of the current process image.)
87 The initial argument for these functions is the name of a file that is
92 and subsequent ellipses in the
97 functions can be thought of as
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
108 be terminated by a null pointer,
109 and, since these are variadic functions, this pointer must be cast
110 .IR "(char\ *) NULL" .
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
123 be terminated by a null pointer.
129 functions allow the caller to specify the environment of the
130 executed program via the argument
134 argument is an array of pointers to null-terminated strings and
136 be terminated by a null pointer.
137 The other functions take the environment for the new process
138 image from the external variable
140 in the calling process.
141 .SS Special semantics for execlp() and execvp()
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
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) .
160 call typically returns the value "/bin:/usr/bin".)
162 If the specified filename includes a slash character, then
164 is ignored, and the file at the specified pathname is executed.
166 In addition, certain errors are treated specially.
168 If permission is denied for a file (the attempted
170 failed with the error
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
179 If the header of a file isn't recognized (the attempted
181 failed with the error
183 these functions will execute the shell
185 with the path of the file as its first argument.
186 (If this attempt fails, no further searching is done.)
190 functions return only if an error has occurred.
191 The return value is \-1, and
193 is set to indicate the error.
195 All of these functions may fail and set
197 for any of the errors specified for
202 function first appeared in glibc 2.11.
204 For an explanation of the terms used in this section, see
210 Interface Attribute Value
215 T} Thread safety MT-Safe
220 T} Thread safety MT-Safe env
223 POSIX.1-2001, POSIX.1-2008.
227 function is a GNU extension.
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
235 as an anti-Trojan-horse measure.
237 traditional "current directory first" default path.
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
246 BSD (and possibly other systems) do an automatic
250 Linux treats it as a hard
251 error and returns immediately.
253 Traditionally, the functions
257 ignored all errors except for the ones described above and
261 upon which they returned.
262 They now return if any error other than the ones
263 described above occurs.