Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sh(1)

chdir(2)

chroot(2)

close(2)

exit(2)

fcntl(2V)

fork(2)

getgroups(2)

getitimer(2)

getpid(2)

getrlimit(2)

getrusage(2)

profil(2)

ptrace(2)

semop(2)

setpgrp(2V)

shmop(2)

sigvec(2)

execl(3)

termio(4)

a.out(5)

environ(5V)

EXECVE(2)  —  SYSTEM CALLS

NAME

execve − execute a file

SYNOPSIS

int execve(path, argv, envp)
char ∗path, ∗∗argv, ∗∗envp;

DESCRIPTION

execve() transforms the calling process into a new process.  The new process is constructed from an ordinary file, whose name is pointed to by path, called the newprocessfile. 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 may be specified by the header to be initialized with zero data.  See a.out(5). 

An interpreter file begins with a line of the form ‘#! interpreter [arg]’.  When an interpreter file is execve’d, the system execve’s the specified interpreter. If the optional arg is specified, it becomes the first argument to the interpreter, and the name of the originally execve’d file becomes the second argument; otherwise, the name of the originally execve’d file becomes the first argument.  The original argument are shifted over to become the subsequent arguments.  The zeroth argument, normally the name of the execve’d file, is left unchanged. 

There can be no return from a successful execve() because the calling core image is lost.  This is the mechanism whereby different process images become active. 

The argument argv is a pointer to a NULL-terminated 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 (that is, the last component of path).

The argument envp is also a pointer to a NULL-terminated array of character pointers to null-terminated strings.  These strings pass information to the new process which are not directly arguments to the command (see environ(5V)). 

Descriptors open in the calling process remain open in the new process, except for those for which the close-on-exec flag is set (see close(2) and fcntl(2V)).  Descriptors which remain open are unaffected by execve. 

Ignored signals remain ignored across an execve, but signals that are caught are reset to their default values.  Blocked signals remain blocked regardless of changes to the signal action.  The signal stack is reset to be undefined (see sigvec(2) for more information). 

Each process has a real user ID and group ID and an effective user ID and group ID.  The real ID identifies the person using the system; the effective ID determines their access privileges.  execve() changes the effective user or group ID to the owner or group of the executed file if the file has the “set-user-ID” or “set-group-ID” modes.  The real user ID and group ID are not affected. 

The shared memory segments attached to the calling process will not be attached to the new process (see shmop(2)). 

Profiling is disabled for the new process; see profil(2). 

The new process also inherits the following attributes from the calling process:

process IDsee
getpid(2)
parent process IDsee
getpid(2)
process group IDsee
setpgrp(2V)
access groupssee
getgroups(2)
semadj valuessee
semop(2)
working directorysee
chdir(2)
root directorysee
chroot(2)
control terminalsee
termio(4)
trace flagsee
ptrace(2) request 0)
resource usagessee
getrusage(2)
interval timerssee
getitimer(2)
resource limitssee
getrlimit(2)
file mode masksee
umask(2)
signal masksee
sigvec(2),
sigsetmask(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 points to the array of character pointers to the arguments themselves. 

envp 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 variable environ.  Each string consists of a name, an “=”, and a null-terminated value.  The array of pointers is terminated by a null pointer.  The shell sh(1) passes an environment entry for each global shell variable defined when the program is called.  See environ(5V) for some conventionally used names. 

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:

ENOTDIR A component of the path prefix of the new process file is not a directory. 

ENAMETOOLONG The length of a component of path exceeds 255 characters, or the length of path exceeds 1023 characters. 

ENOENT One or more components of the path prefix of the new process file does not exist. 

ENOENT The new process file does not exist. 

ELOOP Too many symbolic links were encountered in translating path.

EACCES Search permission is denied for a component of the new process file’s path prefix. 

EACCES The new process file is not an ordinary file. 

EACCES Execute permission is denied for the new process file. 

ENOEXEC The new process file has the appropriate access permission, but has an invalid magic number in its header. 

ENOMEM The new process file requires more virtual memory than is allowed by the imposed maximum (getrlimit(2)). 

E2BIG The number of bytes in the new process file’s argument list is larger than the system-imposed limit.  The limit in the system as released is 1,048,576 bytes ( NCARGS in <sys/param.h>). 

EFAULT The new process file is not as long as indicated by the size values in its header. 

EFAULT path, argv, or envp points to an illegal address. 

EIO An I/O error occurred while reading from the file system. 

CAVEATS

If a program is setuid() to a non-super-user, but is executed when the real user ID is super-user, then the program has some of the powers of a super-user as well. 

SEE ALSO

sh(1), chdir(2), chroot(2), close(2), exit(2), fcntl(2V), fork(2), getgroups(2), getitimer(2), getpid(2), getrlimit(2), getrusage(2), profil(2), ptrace(2), semop(2), setpgrp(2V), shmop(2), sigvec(2), execl(3), termio(4), a.out(5), environ(5V)

Sun Release 4.0  —  Last change: 22 November 1987

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