1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" @(#)exec.3 6.4 (Berkeley) 4/19/91
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
36 .\" Modified, 24 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
37 .\" Added note on casting NULL
39 .TH EXEC 3 2010-09-25 "GNU" "Linux Programmer's Manual"
41 execl, execlp, execle, execv, execvp, execvpe \- execute a file
43 .B #include <unistd.h>
45 .B extern char **environ;
47 .BI "int execl(const char *" path ", const char *" arg ", ...);"
49 .BI "int execlp(const char *" file ", const char *" arg ", ...);"
51 .BI "int execle(const char *" path ", const char *" arg ,
53 .BI " ..., char * const " envp "[]);"
55 .BI "int execv(const char *" path ", char *const " argv "[]);"
57 .BI "int execvp(const char *" file ", char *const " argv "[]);"
59 .BI "int execvpe(const char *" file ", char *const " argv "[],"
61 .BI " char *const " envp "[]);"
64 Feature Test Macro Requirements for glibc (see
65 .BR feature_test_macros (7)):
73 family of functions replaces the current process image with a new process
75 The functions described in this manual page are front-ends for
77 (See the manual page for
79 for further details about the replacement of the current process image.)
81 The initial argument for these functions is the name of a file that is
86 and subsequent ellipses in the
91 functions can be thought of as
96 Together they describe a list of one or more pointers to null-terminated
97 strings that represent the argument list available to the executed program.
98 The first argument, by convention, should point to the filename associated
99 with the file being executed.
100 The list of arguments
102 be terminated by a NULL
103 pointer, and, since these are variadic functions, this pointer must be cast
104 .IR "(char *) NULL" .
111 functions provide an array of pointers to null-terminated strings that
112 represent the argument list available to the new program.
113 The first argument, by convention, should point to the filename
114 associated with the file being executed.
115 The array of pointers
117 be terminated by a NULL pointer.
123 functions allow the caller to specify the environment of the
124 executed program via the argument
128 argument is an array of pointers to null-terminated strings and
130 be terminated by a NULL pointer.
131 The other functions take the environment for the new process
132 image from the external variable
134 in the calling process.
135 .SS Special semantics for execlp() and execvp()
142 functions duplicate the actions of the shell in
143 searching for an executable file
144 if the specified filename does not contain a slash (/) character.
145 The file is sought in the colon-separated list of directory pathnames
148 environment variable.
149 If this variable isn't defined, the path list defaults to
150 the current directory followed by the list of directories returned by
151 .IR confstr(_CS_PATH) .
154 call typically returns the value "/bin:/usr/bin".)
156 If the specified filename includes a slash character, then
158 is ignored, and the file at the specified pathname is executed.
160 In addition, certain errors are treated specially.
162 If permission is denied for a file (the attempted
164 failed with the error
166 these functions will continue searching the rest of the search path.
167 If no other file is found, however,
168 they will return with
173 If the header of a file isn't recognized (the attempted
175 failed with the error
177 these functions will execute the shell
179 with the path of the file as its first argument.
180 (If this attempt fails, no further searching is done.)
184 functions only return if an error has have occurred.
185 The return value is \-1, and
187 is set to indicate the error.
189 All of these functions may fail and set
191 for any of the errors specified for
196 function first appeared in glibc 2.11.
198 POSIX.1-2001, POSIX.1-2008.
202 function is a GNU extension.
204 On some other systems, the default path (used when the environment
205 does not contain the variable \fBPATH\fR) has the current working
206 directory listed after
210 as an anti-Trojan-horse measure.
212 traditional "current directory first" default path.
218 when errors occur while attempting to execute the file is historic
219 practice, but has not traditionally been documented and is not specified by
221 BSD (and possibly other systems) do an automatic
225 Linux treats it as a hard
226 error and returns immediately.
228 Traditionally, the functions
232 ignored all errors except for the ones described above and
236 upon which they returned.
237 They now return if any error other than the ones
238 described above occurs.