Open System Services System Calls Reference Manual (G06.25+, H06.03+)
execvp(2) OSS System Calls Reference Manual
Entering the New Process
When a program is executed as a result of a call to a function in the exec set of functions, it is
entered as a function call as follows:
int main(
int argc,
char ∗∗argv[],
char ∗∗env[]);
Here, the argc parameter is the argument count, the argv[]parameter is an array of character
pointers to the arguments themselves, and env[]is a pointer to a character array listing the
environment variables. The argv[]array is terminated by a null pointer. The null pointer is not
counted in argc.
The arguments specified by a program with one of the exec set of functions are passed on to the
new process image in the corresponding arguments to the
main() function.
The env[]parameter for the main function is an HP extension and is not the preferred method of
obtaining the environment variables for the new process. Use of the **environ array is the pre-
ferred method.
Passing the Arguments and the Environment
The number of bytes available for the new process’s combined argument and environment lists
has a system-imposed limit. This limit, which includes the pointers and the null terminators on
the strings, is available by calling the sysconf(_SC_ARG_MAX) function.
Executing a Binary File
If the file specified in the function call is a binary executable file, the function loads the file
directly.
Executing a Text File
If the file specified in the function call is not a binary executable file, the function examines the
file to determine whether it is an executable text file. The function checks for a header line in the
following format:
#! interpreter_name [optional_string]
The #! notation identifies the file as an executable text file. The new process image filename is
constructed from the process image filename in the interpreter_name string, treating it like the
path parameter. The arguments passed to the new process are modified as follows:
• The argv[0] parameter is set to the name of the interpreter.
• If the optional_string portion is present, argv[1] is set to optional_string.
• The next element of argv[]is set to the original value of file.
• The remaining elements of argv[]are set to the original elements of argv[], starting with
argv[1].
• The original argv[0] is discarded.
The S_ISUID and S_ISGID mode bits of an executable text file are honored. Those bits of the
interpreter_name command interpreter are ignored.
When the File Is Invalid
If the process image file is not a valid executable object, or if the text file does not contain the
header line, the execvp() function invokes the /bin/sh command interpreter as the new process
image and pass the following arguments to it:
2−44 Hewlett-Packard Company 527186-003