[Previous] [Contents] [Next]

spawnvpe()

Spawn a child process, given a vector of arguments, an environment, and a relative path

Synopsis:

#include <spawn.h>

int spawnvpe( int mode, 
              const char * file, 
              char * const argv[], 
              char * const envp[] );

Library:

libc

Description:

The spawnvpe() function creates and executes a new child process, named in file with the NULL-terminated list of arguments in the argv vector.

The spawnvpe() function isn't a POSIX 1003.1 function, and isn't guaranteed to behave the same on all operating systems. It calls spawnp().


How the spawn functions are related


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:

P_WAIT
The child program is loaded into available memory, is executed, dies and then the parent program resumes execution.
P_NOWAIT
Causes the parent program to execute concurrently with the new child process.
P_NOWAITO
Causes the parent program to execute concurrently with the new child process. The wait() function can't be used to obtain the exit code.
P_OVERLAY
The child program replaces the parent program in memory and is executed. No return is made to the parent program. This is equivalent to calling the appropriate exec*() function.

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.

The argv argument is a pointer to an argument vector. The value in argv[0] should point to a filename that's associated with the program being loaded. The last member of argv must be a NULL pointer. The value of argv can't be NULL, and argv[0] can't be a NULL pointer, even if no argument strings are passed.

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>).


Note: A parent/child relationship doesn't imply that the child process dies when the parent process dies.

Returns:

The spawnvpe() 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 cannot get the exit status of a P_NOWAITO process.

If an error occurs, -1 is returned (errno is set).

Errors:

E2BIG
The number of bytes used by the argument list or environment list of the new child process is greater than ARG_MAX bytes.
EACCESS
Search permission is denied for a directory listed in the path prefix of the new child process or the new child process file doesn't have the execute bit set.
EAGAIN
Insufficient resources available to create the child process.
EFAULT
One of the buffers specified in the function call is invalid.
ELOOP
Too many levels of symbolic links or prefixes.
ENAMETOOLONG
The length of file plus its path exceeds PATH_MAX or a pathname component is longer than NAME_MAX.
ENOENT
The file identified by the file argument is empty, or one or more components of the pathname of the child process don't exist.
ENOEXEC
The child process file has the correct permissions, but isn't in the correct format for an executable.
ENOMEM
Insufficient memory available to create the child process.
ENOSYS
The spawnvpe() function isn't implemented for the filesystem specified in file.
ENOTDIR
A component of the path prefix of the child process isn't a directory.

Classification:

QNX 4

Safety:
Cancellation point Read the Caveats
Interrupt handler No
Signal handler No
Thread Yes

Caveats:

If mode is P_WAIT, this function is a cancellation point.

See also:

execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), getenv(), putenv(), setenv(), spawn(), spawnp(), spawnve(), wait(), waitpid()


[Previous] [Contents] [Next]