]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/exec.3
Small rewording.
[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@gmail.com>
37 .\" Added note on casting NULL
38 .\"
39 .TH EXEC 3 2008-07-10 "GNU" "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.
63 The functions described in this manual page are front-ends for
64 .BR execve (2).
65 (See the manual page for
66 .BR execve (2)
67 for further details about the replacement of the current process image.)
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.
88 The list of arguments
89 .I must
90 be terminated by a NULL
91 pointer, and, since these are variadic functions, this pointer must be cast
92 .IR "(char *) NULL" .
93 .PP
94 The
95 .BR execv ()
96 and
97 .BR execvp ()
98 functions provide an array of pointers to null-terminated strings that
99 represent the argument list available to the new program.
100 The first argument, by convention, should point to the filename
101 associated with the file being executed.
102 The array of pointers
103 .I must
104 be terminated by a NULL pointer.
105 .PP
106 The
107 .BR execle ()
108 function also specifies the environment of the executed process by following
109 the NULL
110 pointer that terminates the list of arguments in the parameter list or the
111 pointer to the argv array with an additional parameter.
112 This additional
113 parameter is an array of pointers to null-terminated strings and
114 .I must
115 be terminated by a NULL pointer.
116 The other functions take the environment for the new process
117 image from the external variable
118 .I environ
119 in the current process.
120 .SS Special semantics for execlp() and execvp()
121 .PP
122 The functions
123 .BR execlp ()
124 and
125 .BR execvp ()
126 will duplicate the actions of the shell in searching for an executable file
127 if the specified filename does not contain a slash (/) character.
128 The search path is the path specified in the environment by the
129 .B PATH
130 variable.
131 If this variable isn't specified, the default path
132 ":/bin:/usr/bin" is used.
133 In addition, certain
134 errors are treated specially.
135 .PP
136 If permission is denied for a file (the attempted
137 .BR execve (2)
138 returned
139 .BR EACCES ),
140 these functions will continue searching the rest of the search path.
141 If no other file is found, however,
142 they will return with the global variable
143 .I errno
144 set to
145 .BR EACCES .
146 .PP
147 If the header of a file isn't recognized (the attempted
148 .BR execve (2)
149 returned
150 .BR ENOEXEC ),
151 these functions will execute the shell
152 .RI ( /bin/sh )
153 with the path of the file as its first argument.
154 (If this attempt fails, no further searching is done.)
155 .SH "RETURN VALUE"
156 If any of the
157 .BR exec ()
158 functions returns, an error will have occurred.
159 The return value is \-1,
160 and the global variable
161 .I errno
162 will be set to indicate the error.
163 .SH ERRORS
164 All of these functions may fail and set
165 .I errno
166 for any of the errors specified for the library function
167 .BR execve (2).
168 .SH "CONFORMING TO"
169 POSIX.1-2001.
170 .SH NOTES
171 On some other systems the default path (used when the environment
172 does not contain the variable \fBPATH\fR) has the current working
173 directory listed after
174 .I /bin
175 and
176 .IR /usr/bin ,
177 as an anti-Trojan-horse measure.
178 Linux uses here the
179 traditional "current directory first" default path.
180 .PP
181 The behavior of
182 .BR execlp ()
183 and
184 .BR execvp ()
185 when errors occur while attempting to execute the file is historic
186 practice, but has not traditionally been documented and is not specified by
187 the POSIX standard.
188 BSD (and possibly other systems) do an automatic
189 sleep and retry if
190 .B ETXTBSY
191 is encountered.
192 Linux treats it as a hard
193 error and returns immediately.
194 .PP
195 Traditionally, the functions
196 .BR execlp ()
197 and
198 .BR execvp ()
199 ignored all errors except for the ones described above and
200 .B ENOMEM
201 and
202 .BR E2BIG ,
203 upon which they returned.
204 They now return if any error other than the ones
205 described above occurs.
206 .SH "SEE ALSO"
207 .BR sh (1),
208 .BR execve (2),
209 .BR fork (2),
210 .BR ptrace (2),
211 .BR fexecve (3),
212 .BR environ (7)