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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)exec.3 8.3 (Berkeley) 1/24/94
47 .Vt extern char **environ ;
49 .Fn execl "const char *path" "const char *arg" ... NULL
51 .Fn execlp "const char *file" "const char *arg" ... NULL
53 .Fn execle "const char *path" "const char *arg" ... NULL "char *const envp[]"
56 .Fn exect "const char *path" "char *const argv[]" "char *const envp[]"
58 .Fn execv "const char *path" "char *const argv[]"
60 .Fn execvp "const char *file" "char *const argv[]"
62 .Fn execvP "const char *file" "const char *search_path" "char *const argv[]"
66 family of functions replaces the current process image with a
68 The functions described in this manual page are front-ends for the function
70 (See the manual page for
72 for detailed information about the replacement of the current process.)
74 The initial argument for these functions is the pathname of a file which
79 and subsequent ellipses in the
84 functions can be thought of as
89 Together they describe a list of one or more pointers to null-terminated
90 strings that represent the argument list available to the executed program.
91 The first argument, by convention, should point to the file name associated
92 with the file being executed.
105 functions provide an array of pointers to null-terminated strings that
106 represent the argument list available to the new program.
107 The first argument, by convention, should point to the file name associated
108 with the file being executed.
109 The array of pointers
119 functions also specify the environment of the executed process by following
122 pointer that terminates the list of arguments in the argument list
123 or the pointer to the argv array with an additional argument.
124 This additional argument is an array of pointers to null-terminated strings
130 The other functions take the environment for the new process image from the
133 in the current process.
135 Some of these functions have special semantics.
142 will duplicate the actions of the shell in searching for an executable file
143 if the specified file name does not contain a slash
150 search path is the path specified in the environment by
153 If this variable is not specified,
154 the default path is set according to the
159 .Dq Ev /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin .
162 the search path is specified as an argument to the function.
163 In addition, certain errors are treated specially.
165 If an error is ambiguous (for simplicity, we shall consider all
168 as being ambiguous here, although only the critical error
170 is really ambiguous),
171 then these functions will act as if they stat the file to determine
172 whether the file exists and has suitable execute permissions.
173 If it does, they will return immediately with the global variable
175 restored to the value set by
177 Otherwise, the search will be continued.
178 If the search completes without performing a successful
180 or terminating due to an error,
181 these functions will return with the global variable
187 according to whether at least one file with suitable execute permissions
190 If the header of a file is not recognized (the attempted
194 these functions will execute the shell with the path of
195 the file as its first argument.
196 (If this attempt fails, no further searching is done.)
200 executes a file with the program tracing facilities enabled (see
205 functions returns, an error will have occurred.
206 The return value is \-1, and the global variable
208 will be set to indicate the error.
210 .Bl -tag -width /bin/sh -compact
215 Historically, the default path for the
220 .Dq Pa :/bin:/usr/bin .
221 This was changed to remove the current directory to enhance system
228 when errors occur while attempting to execute the file is not quite historic
229 practice, and has not traditionally been documented and is not specified
234 Traditionally, the functions
238 ignored all errors except for the ones described above and
240 upon which they retried after sleeping for several seconds, and
244 upon which they returned.
247 and determine existence and executability more carefully.
250 for inaccessible directories in the path prefix is no longer
253 for files with unsuitable execute permissions.
256 they returned upon all errors except
262 This was inferior to the traditional error handling,
263 since it breaks the ignoring of errors for path prefixes
264 and only improves the handling of the unusual ambiguous error
266 and the unusual error
268 The behaviour was changed to match the behaviour of
281 for any of the errors specified for the library functions
293 for any of the errors specified for the library function
315 function first appeared in
329 is a historical accident and no sane implementation should modify the provided
331 The bogus parameter types trigger false positives from
333 correctness analyzers.
338 macro may be used to work around this limitation.
340 Due to a fluke of the C standard, on platforms other than
344 may be the untyped number zero, rather than a
347 To distinguish the concepts, they are referred to as a
348 .Dq null pointer constant
352 On exotic computer architectures that
354 does not support, the null pointer constant and null pointer may have a
355 different representation.
356 In general, where this document and others reference a
358 value, they actually imply a null pointer.
359 E.g., for portability to non-FreeBSD operating systems on exotic computer
360 architectures, one may use