Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exit(2)

fork(2)

execl(3)

EXECVE(2)

NAME

execve − execute a file

USAGE

execve(name, argv, envp)
char *name, *argv[], *envp[];

DESCRIPTION

Execve 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.  You can initialize additional pages with with zero data with the header. 

An interpreter file begins with a line of the form “#! interpreter”.  When you execve an interpreter file, the system runs execve on the specified interpreter, giving it the name of the original file as an argument and shifting over the rest of the original arguments. 

There is no return from a successful execve because the calling process’ core image is lost.  This is how different process images become active. 

The argument argv is an array of character pointers to null-terminated character strings,  which comprise the argument list that is 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 (i.e., the last component of name). 

The argument envp is also an array of character pointers to null-terminated strings.  These strings pass information that is not in the form of direct arguments to the command. 

Descriptors that were open in the calling process remain open in the new process, except those for which the close-on-exec flag is set; see close(2).  Execve does not affect descriptors that remain open. 

Ignored signals remain ignored across an execve, but signals that are caught are reset to their default values.  The signal stack is reset to undefined; see sigvec(2) for more information. 

Each process has real user and group IDs and an effective user and group IDs.  The real ID identifies the person using the system; the effective ID determines the user’s access privileges.  Execve 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 IDsee getpid(2)
parent process IDsee getppid(2)
process group IDsee getpgrp(2)
access groupssee getgroups(2)
working directorysee chdir(2)
control terminalsee tty(4)
resource usages
interval timerssee getitimer(2)
resource limits
file mode masksee umask(2)
signal masksee sigvec(2)

When the executed program begins, it is called as follows:

main(argc, argv, envp)
int argc;
char **argv, **envp;

where argc is the number of elements in argv (the “arg count”) and argv is the array of character pointers to the arguments themselves. 

Envp is a pointer to an array of strings that constitutes the environment of the process.  A pointer to this array is also stored in the global variable “environ”.  Each string consists of a name, an “=”, and a null-terminated value.  The array of pointers ends with a null pointer.  The Shell passes an environment entry for each global Shell variable defined when the program is called. 

NOTES

If a program is “set-user-ID” to a non-super-user, but is executed when the real “user-ID” is “root,” then the program has the powers of a super-user as well. 

RETURN VALUE

If execve returns to the calling process, an error has occurred; the return value will be −1 and the global variable errno will contain an error code. 

ERRORS

Execve will fail and return to the calling process if one or more of the following are true:

[ENOENT] One or more components of the new process file’s pathname do not exist. 

[ENOTDIR] A component of the new process file is not a directory. 

[EACCES] Search permission is denied for a directory listed in the new process file’s 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 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 (getrlimit(2)). 

[E2BIG] The number of bytes in the new process’ argument list is larger than the system-imposed limit of {ARG_MAX} bytes. 

[EFAULT] The new process file is not as long as the size value indicated in its header. 

[EFAULT] Path, argv, or envp point to an illegal address. 

RELATED INFORMATION

exit(2), fork(2), execl(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026