Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

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)

environ(5)

EXEC(2)  —  HP-UX

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[ ];

DESCRIPTION

Exec, in all its forms, loads a program from an ordinary, executable file onto the current process, replacing the current program. This file is either an executable object file, or a file of data for an interpreter, called a script file.

An executable object file consists of a header (see a.out(4)), a text segment, and a data segment. The data segment contains an initialized portion and an uninitialized portion (bss). For execlp and execvp the shell (/bin/sh) may be loaded to interpret a script instead. There can be no return from a successful exec because the calling program is overlaid by the new 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 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.  (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 a search of 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)), then it is passed to /bin/sh under the assumption that file is 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 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 program.  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.  These strings constitute the environment in which the new program will run.  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.

File descriptors open in the calling process remain open in the new program, 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 program will be set to terminate the new program.  Signals set to be ignored by the calling program will be set to be ignored by the new program.  Signals set to be caught by the calling program will be set to their default value in the new program; 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 program to the owner 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 new program is set to the group ID of the executable file.  The real user ID and real group ID of the new program remain the same as those of the calling program.  Note that the set-user(group)-id function does not apply to scripts, and thus if execlp or execvp executes a script, even if it has the set-user(group)-id bits set, they will be ignored. 

The saved process group ID is set equal to the current process group ID. 

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

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

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

interval timers (see getitimer(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(2))

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

real-time priority (see rtprio(2))

signal mask (see sigvector(2))

pending signals

A script file begins with a line of the form “#!  interpreter” or “#!  interpreter argument”, where #!  must be the first two bytes of the file.  The interpreter name begins with the first character other than space or tab following the #!.  When such a file is exec’d, the system exec’s the specified interpreter, as an executable object file, in its place. Even in the case of execlp or execvp, no path searching is done on the interpreter name.

The argument is anything after any tabs or spaces following the interpreter name on the #!  line, including any imbedded tabs or spaces.  If there is an argument, 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]. 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 #!  line exceeds some system defined maximum number of characters, an error will be posted and exec will not succeed; the line is terminated by either a new line or null character.  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 will be −1 and errno will be set to indicate the error. 

ERRORS

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

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

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

­[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 pointed to by path or file is not executable.  The super-user cannot exec a file unless at least one of the three execute bits is set in the file’s mode. 

­[EACCES] Read permission is denied for the executable file or the interpreter and the process’s trace flag (see ptrace(2) request 0) is set.

­[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 a #!  in its header. 

­[ETXTBSY] The executable file is currently open for writing.  Note: normal executable files are only open for a short time when they start execution.  Other executable file types may be kept open for a long time, or indefinitely under some circumstances. 

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

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

­[EFAULT] The executable file is not as long as indicated by the size values in its header, or is otherwise inconsistent.  The reliable detection of this error will be implementation dependent. 

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

­[ENOENT] Path is null. 

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

­[ENAMETOOLONG] The executable file’s path name or the interpreter’s path name exceeds MAXPATHLEN characters. 

HARDWARE DEPENDENCIES

Series 500
References to memory, such as "text segment", "data segment", "initialized portion", "uninitialized portion", and "bss", are invalid.  See a.out(4) for the Series 500. 

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

Integral PC
Normal users have all super-user capabilities.

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), environ(5). 

Hewlett-Packard Company  —  Version B.1,  May 11, 2021

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