1 .\" Copyright (c) 1991, 1993
2 .\" The Regents of the University of California. 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 8.3 (Berkeley) 1/24/94
33 .\" $FreeBSD: src/lib/libc/gen/exec.3,v 1.23 2003/09/10 19:24:32 ru Exp $
51 .Vt extern char **environ ;
53 .Fn execl "const char *path" "const char *arg" ... /* "(char *)0" */
55 .Fn execlp "const char *file" "const char *arg" ... /* "(char *)0" */
58 .Fa "const char *path" "const char *arg" ...
61 .Fa "(char *)0" "char *const envp[]" */
65 .Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
67 .Fn execv "const char *path" "char *const argv[]"
69 .Fn execvp "const char *file" "char *const argv[]"
71 .Fn execvP "const char *file" "const char *search_path" "char *const argv[]"
75 family of functions replaces the current process image with a
77 The functions described in this manual page are front-ends for the function
79 (See the manual page for
81 for detailed information about the replacement of the current process.)
83 The initial argument for these functions is the pathname of a file which
88 and subsequent ellipses in the
93 functions can be thought of as
98 Together they describe a list of one or more pointers to null-terminated
99 strings that represent the argument list available to the executed program.
100 The first argument, by convention, should point to the file name associated
101 with the file being executed.
102 The list of arguments
114 functions provide an array of pointers to null-terminated strings that
115 represent the argument list available to the new program.
116 The first argument, by convention, should point to the file name associated
117 with the file being executed.
118 The array of pointers
128 functions also specify the environment of the executed process by following
131 pointer that terminates the list of arguments in the argument list
132 or the pointer to the argv array with an additional argument.
133 This additional argument is an array of pointers to null-terminated strings
139 The other functions take the environment for the new process image from the
142 in the current process.
144 Some of these functions have special semantics.
151 will duplicate the actions of the shell in searching for an executable file
152 if the specified file name does not contain a slash
159 search path is the path specified in the environment by
162 If this variable isn't specified,
163 the default path is set according to the
168 .Dq Ev /usr/bin:/bin .
171 the search path is specified as an argument to the function.
172 In addition, certain errors are treated specially.
174 If an error is ambiguous (for simplicity, we shall consider all
177 as being ambiguous here, although only the critical error
179 is really ambiguous),
180 then these functions will act as if they stat the file to determine
181 whether the file exists and has suitable execute permissions.
182 If it does, they will return immediately with the global variable
184 restored to the value set by
186 Otherwise, the search will be continued.
187 If the search completes without performing a successful
189 or terminating due to an error,
190 these functions will return with the global variable
196 according to whether at least one file with suitable execute permissions
199 If the header of a file isn't recognized (the attempted
203 these functions will execute the shell with the path of
204 the file as its first argument.
205 (If this attempt fails, no further searching is done.)
209 executes a file with the program tracing facilities enabled (see
214 functions returns, an error will have occurred.
215 The return value is \-1, and the global variable
217 will be set to indicate the error.
219 .Bl -tag -width /bin/sh -compact
234 for any of the errors specified for the library functions
246 for any of the errors specified for the library function
256 Historically, the default path for the
261 .Dq Pa :/bin:/usr/bin .
262 This was changed to place the current directory last to enhance system
269 when errors occur while attempting to execute the file is not quite historic
270 practice, and has not traditionally been documented and is not specified
275 Traditionally, the functions
279 ignored all errors except for the ones described above and
281 upon which they retried after sleeping for several seconds, and
285 upon which they returned.
288 and determine existence and executability more carefully.
291 for inaccessible directories in the path prefix is no longer
294 for files with unsuitable execute permissions.
297 they returned upon all errors except
303 This was inferior to the traditional error handling,
304 since it breaks the ignoring of errors for path prefixes
305 and only improves the handling of the unusual ambiguous error
307 and the unusual error
309 The behaviour was changed to match the behaviour of
324 function first appeared in