Open System Services System Calls Reference Manual (G06.25+, H06.03+)

execlp(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 specied 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 processs 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 le specied in the function call is a binary executable le, the function loads the le
directly.
Executing a Text File
If the le specied in the function call is not a binary executable le, the function examines the
le to determine whether it is an executable text le. The function checks for a header line in the
following format:
#! interpreter_name [optional_string]
The #! notation identies the le as an executable text le. The new process image lename is
constructed from the process image lename in the interpreter_name string, treating it like the
path parameter. The arguments passed to the new process are modied 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 le.
The remaining elements of argv[]are set to the original elements of argv[], starting with
the second and subsequent values of the arg parameter.
The rst value of arg is discarded.
The S_ISUID and S_ISGID mode bits of an executable text le are honored. Those bits of the
interpreter_name command interpreter are ignored.
When the File Is Invalid
If the process image le is not a valid executable object, or if the text le does not contain the
header line, the execlp() function invokes the /bin/sh command interpreter as the new process
image and pass the following arguments to it:
220 Hewlett-Packard Company 527186-003