OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[linuxjm/LDP_man-pages.git] / original / 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@gmail.com>
37 .\"     Added note on casting NULL
38 .\"
39 .TH EXEC 3  2010-09-25 "GNU" "Linux Programmer's Manual"
40 .SH NAME
41 execl, execlp, execle, execv, execvp, execvpe \- 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 .br
59 .BI "int execvpe(const char *" file ", char *const " argv "[],"
60 .br
61 .BI "           char *const " envp "[]);"
62 .sp
63 .in -4n
64 Feature Test Macro Requirements for glibc (see
65 .BR feature_test_macros (7)):
66 .in
67 .sp
68 .BR execvpe ():
69 _GNU_SOURCE
70 .SH DESCRIPTION
71 The
72 .BR exec ()
73 family of functions replaces the current process image with a new process
74 image.
75 The functions described in this manual page are front-ends for
76 .BR execve (2).
77 (See the manual page for
78 .BR execve (2)
79 for further details about the replacement of the current process image.)
80 .PP
81 The initial argument for these functions is the name of a file that is
82 to be executed.
83 .PP
84 The
85 .I "const char *arg"
86 and subsequent ellipses in the
87 .BR execl (),
88 .BR execlp (),
89 and
90 .BR execle ()
91 functions can be thought of as
92 .IR arg0 ,
93 .IR arg1 ,
94 \&...,
95 .IR argn .
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
101 .I must
102 be terminated by a NULL
103 pointer, and, since these are variadic functions, this pointer must be cast
104 .IR "(char *) NULL" .
105 .PP
106 The
107 .BR execv (),
108 .BR execvp (),
109 and
110 .BR execvpe ()
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
116 .I must
117 be terminated by a NULL pointer.
118 .PP
119 The
120 .BR execle ()
121 and
122 .BR execvpe ()
123 functions allow the caller to specify the environment of the
124 executed program via the argument
125 .IR envp .
126 The
127 .I envp
128 argument is an array of pointers to null-terminated strings and
129 .I must
130 be terminated by a NULL pointer.
131 The other functions take the environment for the new process
132 image from the external variable
133 .I environ
134 in the calling process.
135 .SS Special semantics for execlp() and execvp()
136 .PP
137 The
138 .BR execlp (),
139 .BR execvp (),
140 and
141 .BR execvpe ()
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
146 specified in the
147 .B PATH
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) .
152 (This
153 .BR confstr (3)
154 call typically returns the value "/bin:/usr/bin".)
155
156 If the specified filename includes a slash character, then
157 .B PATH
158 is ignored, and the file at the specified pathname is executed.
159
160 In addition, certain errors are treated specially.
161
162 If permission is denied for a file (the attempted
163 .BR execve (2)
164 failed with the error
165 .BR EACCES ),
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
169 .I errno
170 set to
171 .BR EACCES .
172
173 If the header of a file isn't recognized (the attempted
174 .BR execve (2)
175 failed with the error
176 .BR ENOEXEC ),
177 these functions will execute the shell
178 .RI ( /bin/sh )
179 with the path of the file as its first argument.
180 (If this attempt fails, no further searching is done.)
181 .SH "RETURN VALUE"
182 The
183 .BR exec ()
184 functions only return if an error has have occurred.
185 The return value is \-1, and
186 .I errno
187 is set to indicate the error.
188 .SH ERRORS
189 All of these functions may fail and set
190 .I errno
191 for any of the errors specified for
192 .BR execve (2).
193 .SH VERSIONS
194 The
195 .BR execvpe ()
196 function first appeared in glibc 2.11.
197 .SH "CONFORMING TO"
198 POSIX.1-2001, POSIX.1-2008.
199
200 The
201 .BR execvpe ()
202 function is a GNU extension.
203 .SH NOTES
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
207 .I /bin
208 and
209 .IR /usr/bin ,
210 as an anti-Trojan-horse measure.
211 Linux uses here the
212 traditional "current directory first" default path.
213 .PP
214 The behavior of
215 .BR execlp ()
216 and
217 .BR execvp ()
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
220 the POSIX standard.
221 BSD (and possibly other systems) do an automatic
222 sleep and retry if
223 .B ETXTBSY
224 is encountered.
225 Linux treats it as a hard
226 error and returns immediately.
227 .PP
228 Traditionally, the functions
229 .BR execlp ()
230 and
231 .BR execvp ()
232 ignored all errors except for the ones described above and
233 .B ENOMEM
234 and
235 .BR E2BIG ,
236 upon which they returned.
237 They now return if any error other than the ones
238 described above occurs.
239 .SH "SEE ALSO"
240 .BR sh (1),
241 .BR execve (2),
242 .BR fork (2),
243 .BR ptrace (2),
244 .BR fexecve (3),
245 .BR environ (7)