]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/exec.3
Added SEE ALSO for fexecve.3
[thirdparty/man-pages.git] / man3 / exec.3
1 .\" Copyright (c) 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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.
19 .\"
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
30 .\" SUCH DAMAGE.
31 .\"
32 .\" @(#)exec.3 6.4 (Berkeley) 4/19/91
33 .\"
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@gmx.net>
37 .\" Added note on casting NULL
38 .\"
39 .TH EXEC 3 1993-11-29 "BSD MANPAGE" "Linux Programmer's Manual"
40 .SH NAME
41 execl, execlp, execle, execv, execvp \- execute a file
42 .SH SYNOPSIS
43 .B #include <unistd.h>
44 .sp
45 .B extern char **environ;
46 .sp
47 .BI "int execl(const char *" path ", const char *" arg ", ...);"
48 .br
49 .BI "int execlp(const char *" file ", const char *" arg ", ...);"
50 .br
51 .BI "int execle(const char *" path ", const char *" arg ,
52 .br
53 .BI " ..., char * const " envp "[]);"
54 .br
55 .BI "int execv(const char *" path ", char *const " argv "[]);"
56 .br
57 .BI "int execvp(const char *" file ", char *const " argv "[]);"
58 .SH DESCRIPTION
59 The
60 .BR exec ()
61 family of functions replaces the current process image with a new process
62 image. The functions described in this manual page are front-ends for the
63 function
64 .BR execve (2).
65 (See the manual page for
66 .BR execve ()
67 for detailed information about the replacement of the current process.)
68 .PP
69 The initial argument for these functions is the pathname of a file which is
70 to be executed.
71 .PP
72 The
73 .I "const char *arg"
74 and subsequent ellipses in the
75 .BR execl (),
76 .BR execlp (),
77 and
78 .BR execle ()
79 functions can be thought of as
80 .IR arg0 ,
81 .IR arg1 ,
82 \&...,
83 .IR argn .
84 Together they describe a list of one or more pointers to null-terminated
85 strings that represent the argument list available to the executed program.
86 The first argument, by convention, should point to the filename associated
87 with the file being executed. The list of arguments
88 .I must
89 be terminated by a NULL
90 pointer, and, since these are variadic functions, this pointer must be cast
91 .BR "(char *) NULL" .
92 .PP
93 The
94 .BR execv ()
95 and
96 .BR execvp ()
97 functions provide an array of pointers to null-terminated strings that
98 represent the argument list available to the new program. The first
99 argument, by convention, should point to the filename associated with the
100 file being executed. The array of pointers
101 .I must
102 be terminated by a NULL pointer.
103 .PP
104 The
105 .BR execle ()
106 function also specifies the environment of the executed process by following
107 the NULL
108 pointer that terminates the list of arguments in the parameter list or the
109 pointer to the argv array with an additional parameter. This additional
110 parameter is an array of pointers to null-terminated strings and
111 .I must
112 be terminated by a NULL pointer.
113 The other functions take the environment for the new process
114 image from the external variable
115 .I environ
116 in the current process.
117 .PP
118 Some of these functions have special semantics.
119 .PP
120 The functions
121 .BR execlp ()
122 and
123 .BR execvp ()
124 will duplicate the actions of the shell in searching for an executable file
125 if the specified filename does not contain a slash (/) character. The
126 search path is the path specified in the environment by the
127 .B PATH
128 variable. If this variable isn't specified, the default path
129 ``:/bin:/usr/bin'' is used. In addition, certain
130 errors are treated specially.
131 .PP
132 If permission is denied for a file (the attempted
133 .BR execve ()
134 returned
135 .BR EACCES ),
136 these functions will continue searching the rest of the search path. If no
137 other file is found, however, they will return with the global variable
138 .I errno
139 set to
140 .BR EACCES .
141 .PP
142 If the header of a file isn't recognized (the attempted
143 .BR execve ()
144 returned
145 .BR ENOEXEC ),
146 these functions will execute the shell with the path of the file as its
147 first argument. (If this attempt fails, no further searching is done.)
148 .SH "RETURN VALUE"
149 If any of the
150 .BR exec ()
151 functions returns, an error will have occurred. The return value is \-1,
152 and the global variable
153 .I errno
154 will be set to indicate the error.
155 .SH FILES
156 .I /bin/sh
157 .SH ERRORS
158 All of these functions may fail and set
159 .I errno
160 for any of the errors specified for the library function
161 .BR execve (2).
162 .SH "SEE ALSO"
163 .BR sh (1),
164 .BR execve (2),
165 .BR fork (2),
166 .BR ptrace (2),
167 .BR fexecve (3),
168 .BR environ (5)
169 .SH COMPATIBILITY
170 On some other systems the default path (used when the environment
171 does not contain the variable \fBPATH\fR) has the current working
172 directory listed after
173 .I /bin
174 and
175 .IR /usr/bin ,
176 as an anti-Trojan-horse measure. Linux uses here the
177 traditional "current directory first" default path.
178 .PP
179 The behavior of
180 .BR execlp ()
181 and
182 .BR execvp ()
183 when errors occur while attempting to execute the file is historic
184 practice, but has not traditionally been documented and is not specified by
185 the POSIX standard. BSD (and possibly other systems) do an automatic
186 sleep and retry if ETXTBSY is encountered. Linux treats it as a hard
187 error and returns immediately.
188 .PP
189 Traditionally, the functions
190 .BR execlp ()
191 and
192 .BR execvp ()
193 ignored all errors except for the ones described above and
194 .B ENOMEM
195 and
196 .BR E2BIG ,
197 upon which they returned. They now return if any error other than the ones
198 described above occurs.
199 .SH "CONFORMING TO"
200 .BR execl (),
201 .BR execv (),
202 .BR execle (),
203 .BR execlp ()
204 and
205 .BR execvp ()
206 conform to
207 IEEE Std1003.1-88 (``POSIX.1'').