OSDN Git Service

5b10cec1a113c5ffd9785cd561fb92a405e58f92
[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 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\"    must display the following acknowledgement:
15 .\"     This product includes software developed by the University of
16 .\"     California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\"    may be used to endorse or promote products derived from this software
19 .\"    without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\" %%%LICENSE_END
33 .\"
34 .\"     @(#)exec.3      6.4 (Berkeley) 4/19/91
35 .\"
36 .\" Converted for Linux, Mon Nov 29 11:12:48 1993, faith@cs.unc.edu
37 .\" Updated more for Linux, Tue Jul 15 11:54:18 1997, pacman@cqc.com
38 .\" Modified, 24 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
39 .\"     Added note on casting NULL
40 .\"
41 .TH EXEC 3  2010-09-25 "GNU" "Linux Programmer's Manual"
42 .SH NAME
43 execl, execlp, execle, execv, execvp, execvpe \- execute a file
44 .SH SYNOPSIS
45 .B #include <unistd.h>
46 .sp
47 .B extern char **environ;
48 .sp
49 .BI "int execl(const char *" path ", const char *" arg ", ...);"
50 .br
51 .BI "int execlp(const char *" file ", const char *" arg ", ...);"
52 .br
53 .BI "int execle(const char *" path ", const char *" arg ,
54 .br
55 .BI "           ..., char * const " envp "[]);"
56 .br
57 .BI "int execv(const char *" path ", char *const " argv "[]);"
58 .br
59 .BI "int execvp(const char *" file ", char *const " argv "[]);"
60 .br
61 .BI "int execvpe(const char *" file ", char *const " argv "[],"
62 .br
63 .BI "            char *const " envp "[]);"
64 .sp
65 .in -4n
66 Feature Test Macro Requirements for glibc (see
67 .BR feature_test_macros (7)):
68 .in
69 .sp
70 .BR execvpe ():
71 _GNU_SOURCE
72 .SH DESCRIPTION
73 The
74 .BR exec ()
75 family of functions replaces the current process image with a new process
76 image.
77 The functions described in this manual page are front-ends for
78 .BR execve (2).
79 (See the manual page for
80 .BR execve (2)
81 for further details about the replacement of the current process image.)
82 .PP
83 The initial argument for these functions is the name of a file that is
84 to be executed.
85 .PP
86 The
87 .I "const char\ *arg"
88 and subsequent ellipses in the
89 .BR execl (),
90 .BR execlp (),
91 and
92 .BR execle ()
93 functions can be thought of as
94 .IR arg0 ,
95 .IR arg1 ,
96 \&...,
97 .IR argn .
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 filename associated
101 with the file being executed.
102 The list of arguments
103 .I must
104 be terminated by a null pointer,
105 and, since these are variadic functions, this pointer must be cast
106 .IR "(char\ *) NULL" .
107 .PP
108 The
109 .BR execv (),
110 .BR execvp (),
111 and
112 .BR execvpe ()
113 functions provide an array of pointers to null-terminated strings that
114 represent the argument list available to the new program.
115 The first argument, by convention, should point to the filename
116 associated with the file being executed.
117 The array of pointers
118 .I must
119 be terminated by a null pointer.
120 .PP
121 The
122 .BR execle ()
123 and
124 .BR execvpe ()
125 functions allow the caller to specify the environment of the
126 executed program via the argument
127 .IR envp .
128 The
129 .I envp
130 argument is an array of pointers to null-terminated strings and
131 .I must
132 be terminated by a null pointer.
133 The other functions take the environment for the new process
134 image from the external variable
135 .I environ
136 in the calling process.
137 .SS Special semantics for execlp() and execvp()
138 .PP
139 The
140 .BR execlp (),
141 .BR execvp (),
142 and
143 .BR execvpe ()
144 functions duplicate the actions of the shell in
145 searching for an executable file
146 if the specified filename does not contain a slash (/) character.
147 The file is sought in the colon-separated list of directory pathnames
148 specified in the
149 .B PATH
150 environment variable.
151 If this variable isn't defined, the path list defaults to
152 the current directory followed by the list of directories returned by
153 .IR confstr(_CS_PATH) .
154 (This
155 .BR confstr (3)
156 call typically returns the value "/bin:/usr/bin".)
157
158 If the specified filename includes a slash character, then
159 .B PATH
160 is ignored, and the file at the specified pathname is executed.
161
162 In addition, certain errors are treated specially.
163
164 If permission is denied for a file (the attempted
165 .BR execve (2)
166 failed with the error
167 .BR EACCES ),
168 these functions will continue searching the rest of the search path.
169 If no other file is found, however,
170 they will return with
171 .I errno
172 set to
173 .BR EACCES .
174
175 If the header of a file isn't recognized (the attempted
176 .BR execve (2)
177 failed with the error
178 .BR ENOEXEC ),
179 these functions will execute the shell
180 .RI ( /bin/sh )
181 with the path of the file as its first argument.
182 (If this attempt fails, no further searching is done.)
183 .SH RETURN VALUE
184 The
185 .BR exec ()
186 functions return only if an error has occurred.
187 The return value is \-1, and
188 .I errno
189 is set to indicate the error.
190 .SH ERRORS
191 All of these functions may fail and set
192 .I errno
193 for any of the errors specified for
194 .BR execve (2).
195 .SH VERSIONS
196 The
197 .BR execvpe ()
198 function first appeared in glibc 2.11.
199 .SH CONFORMING TO
200 POSIX.1-2001, POSIX.1-2008.
201
202 The
203 .BR execvpe ()
204 function is a GNU extension.
205 .SH NOTES
206 On some other systems, the default path (used when the environment
207 does not contain the variable \fBPATH\fR) has the current working
208 directory listed after
209 .I /bin
210 and
211 .IR /usr/bin ,
212 as an anti-Trojan-horse measure.
213 Linux uses here the
214 traditional "current directory first" default path.
215 .PP
216 The behavior of
217 .BR execlp ()
218 and
219 .BR execvp ()
220 when errors occur while attempting to execute the file is historic
221 practice, but has not traditionally been documented and is not specified by
222 the POSIX standard.
223 BSD (and possibly other systems) do an automatic
224 sleep and retry if
225 .B ETXTBSY
226 is encountered.
227 Linux treats it as a hard
228 error and returns immediately.
229 .PP
230 Traditionally, the functions
231 .BR execlp ()
232 and
233 .BR execvp ()
234 ignored all errors except for the ones described above and
235 .B ENOMEM
236 and
237 .BR E2BIG ,
238 upon which they returned.
239 They now return if any error other than the ones
240 described above occurs.
241 .SH SEE ALSO
242 .BR sh (1),
243 .BR execve (2),
244 .BR fork (2),
245 .BR ptrace (2),
246 .BR fexecve (3),
247 .BR environ (7)
248 .SH COLOPHON
249 This page is part of release 3.64 of the Linux
250 .I man-pages
251 project.
252 A description of the project,
253 and information about reporting bugs,
254 can be found at
255 \%http://www.kernel.org/doc/man\-pages/.