Updated: October 28, 2024 |
Execute a file
#include <process.h> int execlpe( const char * file, const char * arg0, const char * arg1, … const char * argn, NULL, const char * envp[] );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The execlpe() function replaces the current process image with a new process image specified by file. The new image is constructed from a regular, executable file called the new process image file. No return is made because the calling process image is replaced by the new process image.
The execlpe() function uses the paths listed in the PATH environment variable to locate the program to be loaded, provided that the following conditions are met:
The process is started with the arguments specified in the NULL-terminated arguments arg1…argn. arg0 should point to a filename associated with the program being loaded. Only arg0 is required, arg1…argn are optional.
The new process image's environment is specified in envp, a NULL-terminated array of NULL-terminated strings. envp cannot be NULL, but envp[0] can be a NULL pointer if no environment strings are passed.
Each pointer in envp points to a string in the form:
variable=value
that is used to define an environment variable.
The environment is the collection of environment variables whose values have been defined with the export shell command, the env utility, or by the successful execution of the putenv() or setenv() functions. A program may read these values with the getenv() function.
An error is detected when the program can't be found.
If the file is on a filesystem mounted with the ST_NOSUID flag set, the effective user ID, effective group ID, saved set-user ID and saved set-group ID are unchanged for the new process image. Otherwise, if the set-user ID mode bit is set, the effective user ID of the new process image is set to the owner ID of file. Similarly, if the set-group ID mode bit is set, the effective group ID of the new process image is set to the group ID of file. The real user ID, real group ID and supplementary group IDs of the new process image remain the same as those of the calling process. The effective user ID and effective group ID of the new process image are saved as the saved set-user ID and the saved set-group ID used by setuid().
If the calling process had locked any memory, the locks are released.
Function | Description | POSIX? |
---|---|---|
execl() | NULL-terminated argument list | Yes |
execle() | NULL-terminated argument list, specify the new process image's environment | Yes |
execlp() | NULL-terminated argument list, search for the new process image file in PATH | Yes |
execlpe() | NULL-terminated argument list, search for the new process image file in PATH, specify the new process image's environment | No |
execv() | NULL-terminated array of arguments | Yes |
execve() | NULL-terminated array of arguments, specify the new process image's environment | Yes |
execvp() | NULL-terminated array of arguments, search for the new process image file in PATH | Yes |
execvpe() | NULL-terminated array of arguments, search for the new process image file in PATH, specify the new process image's environment | No |
When execlpe() is successful, it doesn't return; otherwise, it returns -1 and sets errno.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |