Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

alarm(2)

exit(2)

fork(2)

nice(2)

phys(2)

ptrace(2)

semop(2)

setcompat(2)

times(2)

signal(3)

csh(1)

ksh(1)

sh(1)




exec(2) exec(2)
NAME execl, execv, execle, execve, execlp, execvp - execute a file SYNOPSIS int execl(path, arg0, arg1,..., argn, 0); char *path, *arg0, *arg1,..., *argn; int execv(path, argv) char *path, *argv[]; int execle(path, arg0, arg1,..., argn, 0, envp) char *path, *arg0, *arg1,..., *argn, *envp[]; int execve(path, argv, envp) char *path, *argv[], *envp[]; int execlp(file, arg0, arg1,..., argn, 0) char *file, *arg0, *arg1,..., *argn; int execvp(file, argv) char *file, *argv[]; extern char **environ; DESCRIPTION exec in all its forms transforms the calling process into a new process. The new process is constructed from an ordinary, executable file called the ``new process file.'' There can be no return from a successful exec because the calling process is overlaid by the new process. path points to a pathname that identifies the new process file. file points to the new process file. The path prefix for this file is obtained by a search of the directories passed as the environment variable PATH (see environ(5)). The shell is invoked if a command file is found by execlp or execvp. arg0, arg1, ..., argn are pointers to null-terminated character strings. These strings constitute the argument list that is available to the new process. By convention, at least arg0 must be present and point to a string that is the same as path (or its last component). argv is an array of character pointers to null-terminated strings. These strings constitute the argument list that is available to the new process. By convention, argv must have at least one member, and it must point to a string that is the same as path (or its last component). argv is January 1992 1



exec(2) exec(2)
terminated by a null pointer and is directly usable in another execv because argv[argc] is 0. envp is an array of character pointers to null-terminated strings. These strings constitute the environment for the new process. envp is terminated by a null pointer. For execl, execv, execlp, and execvp, the C run-time startoff routine places a pointer to the environment of the calling process in the global cell extern char **environ; and it is used to pass the environment of the calling process to the new process. File descriptors that open during the calling process remain open in the new process, except for those whose close-on- exec flag is set (see fcntl(2)). For those file descriptors that remain open, the file pointer is unchanged. By default, a new process automatically has the system default compatibility flag (see setcompat(2)). However, if the COMPAT_EXEC flag is set in the calling process, the new process inherits the compatibility flag of the calling process. In the A/UX POSIX environment, the compatibility flag always includes COMPAT_EXEC (see setposix(3P)). Signals set to the default action in the calling process are set to the default action in the new process. Signals set to be ignored by the calling process are set to be ignored by the new process. Signals set to be caught by the calling process are set to the default action in the new process. If the set-user-ID mode bit of the new process file is set (see chmod(2)), exec sets the effective user ID of the new process to the owner ID of the new process file. Similarly, if the set-group-ID mode bit of the new process file is set, the effective group ID of the new process is set to the group ID of the new process file. The real user ID and real group ID of the new process remain the same as those of the calling process. The shared-memory segments attached to the calling process are not attached to the new process (see shmop(2)). Profiling is disabled for the new process (see profil(2)). Regions of physical memory mapped into the virtual address space of the calling process are detached from the address space of the new process (see phys(2)). 2 January 1992



exec(2) exec(2)
The new process also inherits the following attributes from the calling process: access groups (see getgroups(2)) nice value (see nice(2)) process ID parent process ID process group ID semadj values (see semop(2)) tty group ID (see exit(2) and signal(3)) trace flag (see ptrace(2) request 0) time left until an alarm clock signal (see alarm(2)) current working directory root directory file-mode-creation mask (see umask(2)) file size limit (see ulimit(2)) utime, stime, cutime, and cstime (see times(2)) execl is useful when a known file with known arguments is being called. The arguments to execl are the character strings constituting the file and the associated arguments. The first argument is conventionally the same as the filename (or its last component). A 0 argument must end the argument list. When a C program is executed, it is called by main(argc, argv, envp) int argc; char **argv, **envp; where argc is the argument count and argv is an array of character pointers to the arguments themselves. As indicated, argc is conventionally at least 1, and the first member of the array points to a string containing the name of the file. envp is a pointer to an array of strings that constitute the environment of the process. Each string consists of a name, an equals sign (=), 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(5) for some conventionally used names. The C run-time startoff routine places a copy of envp in the global cell environ, which is used by execv and execl to pass the environment to any subprograms executed by the current program. The exec routines use lower-level routines, as follows, to pass an environment explicitly: execve(file, argv, environ); execle(file, arg0, arg1, ... , argn, 0, environ); January 1992 3



exec(2) exec(2)
execlp and execvp are called with the same arguments as execl and execv; however, they duplicate the actions of the shell in searching for an executable file in a list of directories. The directory list is obtained from the environment. STATUS MESSAGES AND VALUES If exec returns to the calling process, an error has occurred; the return value is -1 and errno is set to indicate the error. The exec command will fail and return to the calling process if one or more of the following is true: ENOENT One or more components of the pathname of the new process file do not exist. ENAMETOOLONG A component of a pathname exceeded NAME_MAX characters, or an entire pathname exceeded PATH_MAX. ELOOP Too many symbolic links were encountered in translating a pathname. ENOTDIR A component of the path prefix of the new process file prefix is not a directory. EACCES Search permission is denied for a directory listed in the path prefix of the new process file. EACCES The new process file is not an ordinary file. EACCES The new-process-file mode denies execution permission. EAGAIN The system has temporarily exhausted its available memory or swap space. ENOEXEC The exec is not an execlp or execvp, and the new process file has the appropriate access permission but 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 by some 4 January 1992



exec(2) exec(2)
process. Note: If you are running a network file system (NFS) and you are accessing a shared binary remotely, it is possible that you will not get this errno. ENOMEM The new process requires more memory than is allowed by the system-imposed maximum (MAXMEM). E2BIG The number of bytes in the argument list of the new process is greater than the system-imposed limit of ARG_MAX. EFAULT The new process file is not as long as indicated by the size values in its header. EFAULT The pointers path, argv, or envp indicate an illegal address. SEE ALSO alarm(2), exit(2), fork(2), nice(2), phys(2), ptrace(2), semop(2), setcompat(2), times(2), signal(3) csh(1), ksh(1), sh(1) in A/UX Command Reference January 1992 5

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