![]() |
![]() |
![]() |
Spawn a child process, given a list of arguments, an environment, and a relative path
#include <process.h> int spawnlpe( int mode, const char * file, const char * arg0, const char * arg1..., const char * argn, NULL, const char * envp[] );
libc
The spawnlpe() function creates and executes a new child process, named in file with NULL-terminated list of arguments in arg0 ... argn and with the environment specified in envp.
The spawnlpe() function isn't a POSIX 1003.1 function, and isn't guaranteed to behave the same on all operating systems. It builds argv[ ] and envp[ ] arrays before calling spawnp().
Most of the spawn*() functions do a lot of work before a message is sent to procnto.
The value of mode determines how the child process is loaded, and how the parent program behaves after the child program is initiated:
The file argument is used as the pathname of the executable if it contains a slash; otherwise, the PATH environment variable is searched for file.
Arguments are passed to the child process by supplying one or more pointers to character strings as arguments. These character strings are concatenated with spaces inserted to separate the arguments to form one argument string for the child process. At least one argument, arg0, must be passed to the child process. By convention, this first argument is a pointer to the name of the new child process.
The envp argument is a pointer to an array of character pointers, each pointing to a string defining an environment variable. The array is terminated with a NULL pointer. Each pointer points to a character string of the form:
variable=value
that's used to define an environment variable. If the value of envp is NULL, then the child process inherits the environment of the parent process.
The new process can access the calling process environment by using the environ global variable (found in <unistd.h>).
![]() |
A parent/child relationship doesn't imply that the child process dies when the parent process dies. |
The spawnlpe() function's return value depends on the mode argument:
mode | Return value |
---|---|
P_WAIT | The exit status of the child process. |
P_NOWAIT | The process ID of the child process. To get the exit status for a P_NOWAIT process, you must use the waitpid() function, giving it this process ID. |
P_NOWAITO | The process ID of the child process, or 0 if the process is being started on a remote node. You can't get the exit status of a P_NOWAITO process. |
If an error occurs, -1 is returned (errno is set).
Safety: | |
---|---|
Cancellation point | Read the Caveats |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
If mode is P_WAIT, this function is a cancellation point.
execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), getenv(), putenv(), setenv(), spawn(), spawnle(), spawnp(), spawnve(), wait(), waitpid()
![]() |
![]() |
![]() |