Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

execv(2) OSS System Calls Reference Manual
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 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 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, all forms of the function
examine 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
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 execv() function call fails and errno is set to the value of [ENOEXEC].
Open Files
File descriptors open in the calling process image remain open in the new process image, except
for those:
Whose close-on-exec flag FD_CLOEXEC is set (see the fcntl(2) reference page)
Opened using a Guardian function or procedure call
If the process file segment of the new process image is smaller than the process file segment of
the calling process image and if the calling process image has a large number of file descriptors
open, then the system might not be able to propagate all the open file descriptors to the new pro-
cess image. When this situation occurs, the function call fails and errno is set to the value of
[EMFILE].
228 Hewlett-Packard Company 527186-023