Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ exec(2) — CX/UX 6.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

alarm(2)

exit(2)

fork(2)

nice(2)

ptrace(2)

semop(2)

signal(2)

times(2)

ulimit(2)

umask(2)

out(4)

environ(5)

sh(1)

exec(2)

NAME

execl, execv, execle, execve, execlp, execvp, exect − 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[ ];

SYNOPSIS (4.2BSD)

int exect (path, argv, envp)
char ∗path, ∗argv[ ], ∗envp[ ];

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. 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 (see a.out(4)), a text segment, and a data segment.  The data segment contains an initialized portion and an uninitialized portion (bss). 

An interpreter file begins with a line of the form “#!  interpreter”. When an interpreter file is exec’d, the system execs the specified interpreter, giving it the name of the originally exec’d file as an argument, shifting over the rest of the original arguments.  This feature is not found on AT&T SYSTEM V systems. 

There can be no return from a successful exec because the calling process is overlaid by the new process. 

Path points to a path name 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 line "PATH =" (see environ(5)).  The environment is supplied by the shell (see sh(1)). 

Arg0, arg1, ..., argn are pointers to null-terminated character strings.  These strings constitute the argument list 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 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 terminated by a null pointer. 

Envp is an array of character pointers to null-terminated strings.  Each string consists of a name, an "=", and a null-terminated value.  These strings constitute the environment for the new process.  Envp is terminated by a null pointer.  For execl and execv , the C run-time start-off 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.

The exect version is used when the executed file is to be manipulated with ptrace(2).  The program is forced to single step a single instruction giving the parent an opportunity to manipulate its state. 

File descriptors open in 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. 

Signals set to terminate the calling process will be set to terminate the new process.  Signals set to be ignored by the calling process will be set to be ignored by the new process.  Signals set to be caught by the calling process will be set to terminate new process; see signal(2). 

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 effective user ID and effective group ID of the new process are saved for use by the setuid(2) routine. 

When set-group-ID files are executed, the process inherits the security label of the user and the group of the file.  If the system doesn’t have a privilege with this particular combination of security label and group then execution is denied. 

If the user is operating with an effective user ID of root and the security level of the file is not 0 then execution is denied. 

If the file is suid-to-root and the security level of the file is not 0 then execution is denied. 

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). 

Memory locks established by the calling process via calls to mlockall() or mlock() are removed.  If locked pages in the calling process’ address space are also mapped into other process’ address spaces and are locked by those processes, the locks established by the other processes are unaffected by this process’s call to the exec function. 

Any outstanding asynchronous I/O operations may be cancelled.  An outstanding request will be cancelled if the actual I/O operation has not occured. Otherwise, it is allowed to go through I/O completion. However, on exec() all signals to the process are disabled, which means any signal generated because of the I/O completion will not affect the process.  Those asynchronous I/O operations which are not cancelled complete as if the exec function had not yet occured.  In no event, however, shall the new process image created by the exec function be affected by the presence of outstanding asynchronous I/O operations at the time the exec function is called. 

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

nice value (see nice(2))

process ID

parent process ID

process group ID

access groups (see getgroups(2))

semadj values (see semop(2))

tty group ID (see exit(2) and signal(2))

trace flag (see ptrace(2) request PT_TRACE_ME and PT_TRACE_CHILD)

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))

signal mask (see sigvec(2))

utime, stime, cutime, and cstime (see times(2))

universe (see setuniverse(2))

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

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 one 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, as described earlier. 

exec 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 path name of the file do not exist. 

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

­[EACCES] Search permission is denied for a directory listed in the new process file’s path prefix. 

­[EPERM] The new process file is set-group-ID to a group not defined for execution at the calling process’ current classification level. (B1 only)

­[EPERM] The user is operating as root and the security level of the file is not 0. (B1 only)

­[EPERM] The file is suid-to-root and the security level of the file is not 0. (B1 only)

­[EACCES] The new process file is not an ordinary file. 

­[EACCES] The new process file mode denies execution permission. 

­[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 process. 

­[ENOMEM] The new process requires more memory than is allowed by the system-imposed maximum MAXMEM. 

­[E2BIG] The number of bytes in the new process’s argument list is greater than the system-imposed limit of 5120 bytes. 

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

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

RETURN VALUE

If exec returns to the calling process an error has occurred; the return value will be −1 and errno will be set to indicate the error. 

SEE ALSO

alarm(2), exit(2), fork(2), nice(2), ptrace(2), semop(2), signal(2), times(2), ulimit(2), umask(2), a.out(4), environ(5). 
sh(1) in the CX/UX User’s Reference Manual. 

CX/UX Programmer’s Reference Manual

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