.\" 2007-09-14 Ollie Wild <aaw@google.com>, mtk
.\" Add text describing limits on command-line arguments + environment
.\"
-.TH EXECVE 2 2017-09-15 "Linux" "Linux Programmer's Manual"
+.TH EXECVE 2 2019-05-09 "Linux" "Linux Programmer's Manual"
.SH NAME
execve \- execute program
.SH SYNOPSIS
.B #include <unistd.h>
.PP
-.BI "int execve(const char *" filename ", char *const " argv "[], "
+.BI "int execve(const char *" pathname ", char *const " argv "[], "
.br
.BI " char *const " envp []);
.SH DESCRIPTION
.BR execve ()
-executes the program pointed to by \fIfilename\fP.
-\fIfilename\fP must be either a binary executable, or a script
+executes the program referred to by \fIpathname\fP.
+This causes the program that is currently being run by the calling process
+to be replaced with a new program, with newly initialized stack, heap,
+and (initialized and uninitialized) data segments.
+.PP
+\fIpathname\fP must be either a binary executable, or a script
starting with a line of the form:
.PP
.in +4n
after a successful
.BR execve ().
.PP
-If the set-user-ID bit is set on the program file pointed to by
-\fIfilename\fP,
+If the set-user-ID bit is set on the program file referred to by
+\fIpathname\fP,
then the effective user ID of the calling process is changed
to that of the owner of the program file.
Similarly, when the set-group-ID
.I interpreter
must be a valid pathname for an executable file.
If the
-.I filename
+.I pathname
argument of
.BR execve ()
specifies an interpreter script, then
.PP
.in +4n
.EX
-\fIinterpreter\fP [optional-arg] \fIfilename\fP arg...
+\fIinterpreter\fP [optional-arg] \fIpathname\fP arg...
.EE
.in
.PP
ensures that the new program always has some stack space.)
.\" Ollie: That doesn't include the lists of pointers, though,
.\" so the actual usage is a bit higher (1 pointer per argument).
+Additionally, the total size is limited to 3/4 of the value
+of the kernel constant
+.B _STK_LIM
+(8 Mibibytes).
Since Linux 2.6.25,
-the kernel places a floor of 32 pages on this size limit,
+the kernel also places a floor of 32 pages on this size limit,
so that, even when
.BR RLIMIT_STACK
is set very low,
.TP
.B EACCES
Search permission is denied on a component of the path prefix of
-.I filename
+.I pathname
or the name of a script interpreter.
(See also
.BR path_resolution (7).)
For a more detailed explanation of this error, see NOTES.
.TP
.B EFAULT
-.I filename
+.I pathname
or one of the pointers in the vectors
.I argv
or
.TP
.B ELOOP
Too many symbolic links were encountered in resolving
-.I filename
+.I pathname
or the name of a script or ELF interpreter.
.TP
.B ELOOP
The per-process limit on the number of open file descriptors has been reached.
.TP
.B ENAMETOOLONG
-.I filename
+.I pathname
is too long.
.TP
.B ENFILE
.TP
.B ENOENT
The file
-.I filename
+.I pathname
or a script or ELF interpreter does not exist, or a shared library
.\" FIXME but see http://sourceware.org/bugzilla/show_bug.cgi?id=12241
needed for the file or interpreter cannot be found.
.TP
.B ENOTDIR
A component of the path prefix of
-.I filename
+.I pathname
or a script or ELF interpreter is not a directory.
.TP
.B EPERM
varies across Linux kernel versions:
some will refuse execution of set-user-ID and set-group-ID
executables when this would
-give the user powers she did not have already (and return
+give the user powers they did not have already (and return
.BR EPERM ),
some will just ignore the set-user-ID and set-group-ID bits and
.BR exec ()
int j;
for (j = 0; j < argc; j++)
- printf("argv[%d]: %s\\n", j, argv[j]);
+ printf("argv[%d]: %s\en", j, argv[j]);
exit(EXIT_SUCCESS);
}
char *newenviron[] = { NULL };
if (argc != 2) {
- fprintf(stderr, "Usage: %s <file\-to\-exec>\\n", argv[0]);
+ fprintf(stderr, "Usage: %s <file\-to\-exec>\en", argv[0]);
exit(EXIT_FAILURE);
}
.BR fork (2),
.BR get_robust_list (2),
.BR ptrace (2),
-.BR execl (3),
+.BR exec (3),
.BR fexecve (3),
.BR getopt (3),
.BR system (3),