execve(2) System Calls Manual execve(2)
Name
execve - execute a file
Syntax
execve(name, argv, envp)
char *name, *argv[], *envp[];
Description
The system call transforms the calling process into a new process. The new process is constructed from an ordinary file called the new
process file. This file is either an executable object file, or a file of data for an interpreter. An executable object file consists of
an identifying header, followed by pages of data representing the initial program (text) and initialized data pages. Additional pages can
be specified by the header to be initialized with zero data. For further information, see
An interpreter file begins with a line of the form ``#! interpreter''. When an interpreter file is executed the system executes the speci-
fied interpreter, giving it the name of the originally executed file as an argument, shifting over the rest of the original arguments.
There can be no return from a successful because the calling core image is lost. This is the mechanism whereby different process images
become active.
The argument argv is an array of character pointers to null-terminated character strings. These strings constitute the argument list to be
made available to the new process. By convention, at least one argument must be present in this array, and the first element of this array
should be the name of the executed program, the last component of name.
The argument envp is also an array of character pointers to null-terminated strings. These strings pass information to the new process,
but they are not directly arguments to the command. For further information, see
Descriptors open in the calling process remain open in the new process, except for those for which the close-on-exec flag is set. For fur-
ther information, see Descriptors which remain open are unaffected by
Ignored signals remain ignored across an but signals that are caught are reset to their default values. The signal stack is reset to be
undefined. For further information, see
Each process has real user and group IDs and effective user and group IDs. The real ID identifies the person using the system; the effec-
tive ID determines his access privileges. The system call changes the effective user and group ID to the owner of the executed file if the
file has the set-user-ID or set-group-ID modes. The real user ID is not affected.
The new process also inherits the following attributes from the calling process:
Process ID See getpid(2)
Parent process ID See getpid(2)
Process group ID See getpgrp(2)
Access groups See getgroups(2)
Working directory See chdir(2)
root directory See chroot(2)
Control terminal See tty(4)
Resource usages See getrusage(2)
Interval timers See getitimer(2)
Resource limits See getrlimit(2)
File mode mask See umask(2)
Signal mask See sigvec(2)
When the executed program begins, it is called as follows:
main(argc, argv, envp)
int argc;
char **argv, **envp;
The argc argument is the number of elements in argv (the ``arg count'') and argv is the array of character pointers to the arguments them-
selves.
The envp argument is a pointer to an array of strings that constitute the environment of the process. A pointer to this array is also
stored in the global environ variable. Each string consists of a name, an equal sign ( = ), and a null-terminated value. The array of
pointers is terminated by a null pointer. The shell passes an environment entry for each global shell variable defined when the program is
called. See for some conventionally used names.
If returns to the calling process, an error has occurred; the return value is -1 and the global variable errno contains an error code.
Environment
POSIX, System Five
When your program is compiled using the POSIX or System V environment, the effective user ID and effective group ID of the new process
image are saved (as the saved-set-uid and saved-set-gid) for later use by the and functions.
Restrictions
If a program's effective user ID is not the superuser, but it is executed when the real user ID is root, then the program has the powers of
the superuser.
Diagnostics
The system call fails and returns to the calling process under the following conditions:
[ENOENT] The new process file does not exist.
[ENOTDIR] A component of the path prefix is not a directory.
[EACCES] Search permission is denied for a component of the path prefix.
[EACCES] The new process file is not an ordinary file.
[EACCES] The new process file mode denies execute permission.
[ENOEXEC] The new process file has the appropriate access permission, but it has an invalid magic number in its header.
[ETXTBSY] The new process file is a pure procedure (shared text) file that is currently open for writing or reading by some process.
[ENOMEM] The new process requires more virtual memory than is allowed by the imposed maximum. For further information, see
[E2BIG] The number of bytes in the new process's argument list is larger than the system-imposed limit of {ARG_MAX} bytes.
[EFAULT] The new process file is not as long as indicated by the size values in its header.
[EFAULT] The path, argv, or envp points to an illegal address.
[EIO] An I/O error occurred while reading from the file system.
[ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.
[ELOOP] Too many symbolic links were encountered in translating the pathname.
[EROFS] If binaries cannot be executed from the file system.
[EROFS] If and programs cannot be executed from the file system.
[ESTALE] The file handle given in the argument is invalid. The file referred to by that file handle no longer exists or has been
revoked.
[ETIMEDOUT] A connect request or remote file operation failed because the connected party did not properly respond after a period of
time that is dependent on the communications protocol.
See Also
exit(2), fork(2), execl(3), environ(7)
execve(2)