1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
4 .\" and Copyright (c) 2006 Michael Kerrisk <mtk-manpages@gmx.net>
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified by Michael Haardt <michael@moria.de>
27 .\" Modified 1993-07-21 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified 1994-08-21 by Michael Chastain <mec@shell.portal.com>:
29 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
30 .\" Modified 1999-11-12 by Urs Thuermann <urs@isnogud.escape.de>
31 .\" Modified 2004-06-23 by Michael Kerrisk <mtk-manpages@gmx.net>
32 .\" 2006-09-04 Michael Kerrisk <mtk-manpages@gmx.net>
33 .\" Added list of process attributes that are not preserved on exec().
35 .TH EXECVE 2 2006-09-04 "Linux 2.6.17" "Linux Programmer's Manual"
37 execve \- execute program
39 .B #include <unistd.h>
41 .BI "int execve(const char *" filename ", char *const " argv "[], "
43 .BI " char *const " envp []);
45 \fBexecve\fP() executes the program pointed to by \fIfilename\fP.
46 \fIfilename\fP must be either a binary executable, or a script
47 starting with a line of the form "\fB#! \fIinterpreter \fR[arg]".
48 In the latter case, the interpreter must be a valid pathname for an
49 executable which is not itself a script, which will be invoked as
50 \fBinterpreter\fR [arg] \fIfilename\fR.
52 \fIargv\fP is an array of argument strings passed to the new program.
53 \fIenvp\fP is an array of strings, conventionally of the form
54 \fBkey=value\fR, which are passed as environment to the new
55 program. Both \fIargv\fP and \fIenvp\fP must be terminated by a null
56 pointer. The argument vector and environment can be accessed by the
57 called program's main function, when it is defined as \fBint main(int
58 argc, char *argv[], char *envp[])\fR.
60 \fBexecve\fP() does not return on success, and the text, data, bss, and
61 stack of the calling process are overwritten by that of the program
64 If the current program is being ptraced, a \fBSIGTRAP\fP is sent to it
65 after a successful \fBexecve\fP().
67 If the set-user-ID bit is set on the program file pointed to by
68 \fIfilename\fP, and the calling process is not being ptraced,
69 then the effective user ID of the calling process is changed
70 to that of the owner of the program file.
71 Similarly, when the set-group-ID
72 bit of the program file is set the effective group ID of the calling
73 process is set to the group of the program file.
75 The effective user ID of the process is copied to the saved set-user-ID;
76 similarly, the effective group ID is copied to the saved set-group-ID.
77 This copying takes place after any effective ID changes that occur
78 because of the set-user-ID and set-group-ID permission bits.
80 If the executable is an a.out dynamically-linked
81 binary executable containing
82 shared-library stubs, the Linux dynamic linker
84 is called at the start of execution to bring
85 needed shared libraries into memory
86 and link the executable with them.
88 If the executable is a dynamically-linked ELF executable, the
89 interpreter named in the PT_INTERP segment is used to load the needed
90 shared libraries. This interpreter is typically
91 \fI/lib/ld-linux.so.1\fR for binaries linked with the Linux libc
92 version 5, or \fI/lib/ld-linux.so.2\fR for binaries linked with the
95 All process attributes are preserved during an
99 File descriptors that are marked close-on-exec are closed
100 (see the description of
104 .\" FIXME add some statement about the effect on record locks (fcntl()).
106 The set of pending signals is cleared
107 .RB ( sigpending (2)).
109 The dispositions of any signals that are being caught are
110 reset to being ignored.
112 Any alternate signal stack is not preserved
113 .RB ( sigaltstack (2)).
115 Memory mappings are not preserved
118 Attached System V shared memory segments are detached
121 POSIX shared memory regions are unmapped
124 Open POSIX message queue descriptors are closed
125 .RB ( mq_overview (7)).
127 Any open POSIX named semaphores are closed
128 .RB ( sem_overview (7)).
130 POSIX timers are not preserved
131 .RB ( timer_create (3)).
133 Any open directory streams are closed
136 Memory locks are not preserved
140 Exit handlers are not preserved
144 The process attributes in the preceding list are all specified
146 The following Linux-specific process attributes are also
147 not preserved during an
154 unless a set-user-ID or set-group ID program is being executed,
155 in which case it is cleared.
162 The process name, as set by
167 is reset to the name of the new executable file.
169 The termination signal is reset to SIGCHLD
173 Note the following further points:
175 All threads other than calling thread are destroyed during an
177 Mutexes, condition variables, and other pthreads objects are not preserved.
179 The equivalent of \fIsetlocale(LC_ALL, "C")\fP
180 is executed at program start-up.
182 POSIX.1-2001 specifies that the dispositions of any signals that
183 are ignored or set to the default are left unchanged.
184 POSIX.1-2001 specifies one exception: if SIGCHLD is being ignored,
185 then an implementation may leave the disposition unchanged or
186 reset it to the default; Linux does the former.
188 Any outstanding asynchronous I/O operations are cancelled
192 For the handling of capabilities during
195 .BR capabilities (7).
197 On success, \fBexecve\fP() does not return, on error \-1 is returned, and
199 is set appropriately.
203 The total number of bytes in the environment
210 Search permission is denied on a component of the path prefix of
212 or the name of a script interpreter.
214 .BR path_resolution (2).)
217 The file or a script interpreter is not a regular file.
220 Execute permission is denied for the file or a script or ELF interpreter.
223 The file system is mounted
228 points outside your accessible address space.
231 An ELF executable had more than one PT_INTERP segment (i.e., tried to
232 name more than one interpreter).
235 An I/O error occurred.
238 An ELF interpreter was a directory.
241 An ELF interpreter was not in a recognised format.
244 Too many symbolic links were encountered in resolving
246 or the name of a script or ELF interpreter.
249 The process has the maximum number of files open.
256 The system limit on the total number of open files has been reached.
261 or a script or ELF interpreter does not exist, or a shared library
262 needed for file or interpreter cannot be found.
265 An executable is not in a recognised format, is for the wrong
266 architecture, or has some other format error that means it cannot be
270 Insufficient kernel memory was available.
273 A component of the path prefix of
275 or a script or ELF interpreter is not a directory.
278 The file system is mounted
280 the user is not the superuser,
281 and the file has the set-user-ID or set-group-ID bit set.
284 The process is being traced, the user is not the superuser and the
285 file has the set-user-ID or set-group-ID bit set.
288 Executable was open for writing by one or more processes.
290 SVr4, 4.3BSD, POSIX.1-2001.
291 POSIX.1-2001 does not document the #! behavior
292 but is otherwise compatible.
293 .\" SVr4 documents additional error
294 .\" conditions EAGAIN, EINTR, ELIBACC, ENOLINK, EMULTIHOP; POSIX does not
295 .\" document ETXTBSY, EPERM, EFAULT, ELOOP, EIO, ENFILE, EMFILE, EINVAL,
296 .\" EISDIR or ELIBBAD error conditions.
298 Set-user-ID and set-group-ID processes can not be \fBptrace\fP()d.
300 Linux ignores the set-user-ID and set-group-ID bits on scripts.
302 The result of mounting a filesystem
304 vary between Linux kernel versions:
305 some will refuse execution of set-user-ID and set-group-ID
306 executables when this would
307 give the user powers she did not have already (and return EPERM),
308 some will just ignore the set-user-ID and set-group-ID bits and
312 A maximum line length of 127 characters is allowed for the first line in
313 a #! executable shell script.
315 .\" Some Linux versions have failed to check permissions on ELF
316 .\" interpreters. This is a security hole, because it allows users to
317 .\" open any file, such as a rewinding tape device, for reading. Some
318 .\" Linux versions have also had other security holes in \fBexecve\fP(),
319 .\" that could be exploited for denial of service by a suitably crafted
320 .\" ELF binary. There are no known problems with 2.0.34 or 2.2.15.
322 With Unix V6 the argument list of an
325 while the argument list of
327 was ended by \-1. Thus, this
328 argument list was not directly usable in a further
331 Since Unix V7 both are NULL.
335 .BR path_resolution (2),