Open System Services System Calls Reference Manual (G06.28+, H06.05+)
execle(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 the **environ array of the
new process is the preferred method.
Passing the Arguments and the Environment
Instead of passing the **environ array of the calling process, the environment for the new pro-
cess is provided by following the null pointer that terminates the list of arg parameters with an
additional parameter as if it were declared as:
char ∗∗ const envp[]
The envp[]parameter names an array of character pointers to null-terminated strings. These
strings constitute the environment for the new process image. The environment array is ter-
minated with a null pointer.
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 path.
• The remaining elements of argv[]are set to the original elements of argv[], starting with
the second and subsequent values of the arg parameter.
2−12 Hewlett-Packard Company 527186-007