Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ execve(2) — HP-UX 7.01

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sh(1)

alarm(2)

exit(2)

fork(2)

nice(2)

ptrace(2)

semop(2)

signal(2)

times(2)

ulimit(2)

umask(2)

a.out(4)

acl(5)

environ(5)

signal(5)

EXEC(2)

NAME

execl, execv, execle, execve, execlp, execvp − execute a file

SYNOPSIS

int execl (path, arg0, arg1, ..., argn, (char ∗) 0)
char ∗path, ∗arg0, ∗arg1, ..., ∗argn;

int execv (path, argv)
char ∗path, ∗argv[ ];

int execle (path, arg0, arg1, ..., argn, (char ∗) 0, envp)
char ∗path, ∗arg0, ∗arg1, ..., ∗argn, ∗envp[ ];

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

int execlp (file, arg0, arg1, ..., argn, (char ∗) 0)
char ∗file, ∗arg0, ∗arg1, ..., ∗argn;

int execvp (file, argv)
char ∗file, ∗argv[ ];

DESCRIPTION

Exec, in all its forms, loads a program from an ordinary, executable file onto the current process, replacing the current program. The path or file argument refers to either an executable object file or a file of data for an interpreter.  In this case, the file of data is also called a script file. 

An executable object file consists of a header (see a.out(4)), text segment, and data segment. The data segment contains an initialized portion and an uninitialized portion (bss). For execlp and execvp the shell (/bin/sh) can be loaded to interpret a script instead. A successful call to exec does not return because the new program overwrites the calling program. 

When a C program is executed, it is called as follows:

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

where argc is the argument count and argv is the address of an array of character pointers to the arguments themselves.  As indicated, argc usually has a value of at least one, and the first member of the array points to a string containing the name of the file.  (The exit conditions from main are discussed in exit(2).)

Path points to a path name that identifies the executable file containing the new program. 

File (in execlp or execvp) points to a file name identifying the executable file containing the new program. The path prefix for this file is obtained by searching the directories passed as the environment line "PATH =" (see environ(5)). The environment is supplied by the shell (see sh(1)). If file does not have an executable magic number (magic(4)), it is passed to /bin/sh as a shell script. 

Arg0, arg1, ..., argn are pointers to null-terminated character strings.  These strings constitute the argument list available to the new program.  By convention, at least arg0 must be present and point to a string identical to path or path’s last component.

Argv is an array of character pointers to null-terminated strings.  These strings constitute the argument list available to the new program.  By convention, argv must have at least one member, and must point to a string that is identical to path or path’s last component. Argv is terminated by a null pointer. 

Envp is an array of character pointers to null-terminated strings.  These strings constitute the environment in which the new program runs.  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 program in the global cell:
extern char ∗∗environ;
and it is used to pass the environment of the calling program to the new program.

Open file descriptors remain open, except for those whose close-on-exec flag is set; see fcntl(2). The file offset, access mode, and status flags of open file descriptors are unchanged.

Note that normal executable files are open only briefly, when they start execution.  Other executable file types can be kept open for a long time, or even indefinitely under some circumstances. 

The processing of signals by the process is unchanged by exec, except that signals caught by the process are set to their default value; see signal(2).

If the set-user-ID mode bit of the executable file pointed to by path or file is set (see chmod(2)), exec sets the effective-user-ID of the new process to the user ID of the executable file.  Similarly, if the set-group-ID mode bit of the executable file is set, the effective-group-ID of the process is set to the group ID of the executable file.  The real-user-ID and real-group-ID of the process are unchanged.  Note that the set-user(group)-ID function does not apply to scripts; thus, if execlp or execvp executes a script, the set-user(group)-ID bits are ignored, even if they are set. 

The saved-user-ID and saved-group-ID of the process are always set to the effective-user-ID and effective-group-ID, respectively, of the process at the end of the exec, whether or not set-user(group)-ID is in effect.

The shared memory segments attached to the calling program are not attached to the new program (see shmop(2)).

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

The process also retains the following attributes:

current working directory

file creation mode mask (see umask(2))

file locks (see fcntl(2)), except for files closed-on-exec

file size limit (see ulimit(2))

interval timers (see getitimer(2))

nice value (see nice(2))

parent process ID

pending signals

process ID

process group ID

real user ID

real group ID

real-time priority (see rtprio(2))

root directory (see chroot(2))

semadj values (see semop(2))

session membership

signal mask (see sigvector(2))

supplementary group IDs

time left until an alarm clock signal (see alarm(2))

trace flag (see ptrace(2) PT_SETTRC request)

tms_utime, tms_stime, tms_cutime, and tms_cstime (see times(2))

The initial line of a script file must begin with #!  as the first two bytes, followed by 0 or more spaces, followed by interpreter or interpreter argument. One or more space or tab must separate interpreter and argument. The first line should end with either a new line or null character.

#! interpreter
#! interpreter argument

When the script file is executed, the system executes the specified interpreter as an executable object file.  Even in the case of execlp or execvp, no path searching is done of the interpreter name.

The argument is anything that follows the interpreter and tabs or spaces.  If an argument is given, it is passed to the interpreter as argv[1] and the name of the script file is passed as argv[2]. Otherwise, the name of the script file is passed as argv[1]. The argv[0] is passed as specified in the exec call, unless either argv or argv[0] is null as specified, in which case a pointer to a null string is passed as argv[0]. All other arguments specified in the exec call are passed following the name of the script file (that is, beginning at argv[3] if there is an argument; otherwise at argv[2]).

If the initial line of the script file exceeds a system-defined maximum number of characters, exec fails.  The minimum value for this limit is 32. 

Set-user-ID and set-group-ID bits are honored for the script and not for the interpreter. 

RETURN VALUE

If exec returns to the calling program, an error has occurred; the return value is −1 and errno is set to indicate the error. 

ERRORS

Exec fails and returns to the calling program if one or more of the following is true:

[E2BIG] The number of bytes in the new program’s argument list is greater than the system-imposed limit.  This limit is at least 5120 bytes on HP-UX systems. 

[EACCES] Read permission is denied for the executable file or interpreter, and trace flag (see ptrace(2) request PT_SETTRC) of the process is set.

[EACCES] Search permission is denied for a directory listed in the executable file’s or the interpreter’s path prefix. 

[EACCES] The executable file or the interpreter is not an ordinary file. 

[EACCES] The file described by path or file is not executable.  The superuser cannot execute a file unless at least one access permission bit or entry in its access control list has an execute bit set. 

[EFAULT] Path, argv, or envp point to an illegal address.  The reliable detection of this error is implementation dependent. 

[EFAULT] The executable file is shorter than indicated by the size values in its header, or is otherwise inconsistent.  The reliable detection of this error is implementation dependent. 

[EINVAL] The executable file is incompatible with the architecture on which the exec has been performed, and is presumed to be for a different architecture.  It is not guaranteed that every architecture’s executable files wiill be recognized. 

[ELOOP] Too many symbolic links are encountered in translating the path name. 

[ENAMETOOLONG]
The executable file’s path name or the interpreter’s path name exceeds PATH_MAX bytes, or the length of a component of the path name exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect. 

[ENOENT] Path is null. 

[ENOENT] One or more components of the executable file’s path name or the interpreter’s path name does not exist. 

[ENOEXEC] The exec is not an execlp or execvp, and the executable file has the appropriate access permission, but there is neither a valid magic number nor the characters #!  as the first two bytes of its initial line. 

[ENOEXEC] The number of bytes in the initial line of a script file exceeds the system’s maximum. 

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

[ENOTDIR] A component of the executable file’s path prefix or the interpreter’s path prefix is not a directory. 

[ETXTBSY] The executable file is currently open for writing. 

DEPENDENCIES

Series 800
Unsharable executable files (EXEC_MAGIC magic number produced via the −N option of ld(1)) are not supported. 

SEE ALSO

sh(1), alarm(2), exit(2), fork(2), nice(2), ptrace(2), semop(2), signal(2), times(2), ulimit(2), umask(2), a.out(4), acl(5), environ(5), signal(5). 

STANDARDS CONFORMANCE

environ: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

execl: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

execle: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

execlp: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

execv: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

execve: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

execvp: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1

Hewlett-Packard Company  —  HP-UX Release 7.0: Sept 1989

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