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