QNX Developer Support
|This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs.|
Spawn a child process, given a vector of arguments and a relative path
#include <process.h> int spawnvp( int mode, const char * file, char * const argv );
- How you want to load the child process, and how you want the parent
program to behave after the child program is initiated:
- P_WAIT -- load the child program into available memory, execute it, and make the parent program resume execution after the child process ends.
- P_NOWAIT -- execute the parent program concurrently with the new child process.
- P_NOWAITO -- execute the parent program concurrently with the new child process. You can't use wait() to obtain the exit code.
- P_OVERLAY -- replace the parent program with the child program in memory and execute the child. No return is made to the parent program. This is equivalent to calling the appropriate exec*() function.
- The name of the executable file. If this argument contains a slash, it's used as the pathname of the executable; otherwise, the function searches for file in the directories listed in the PATH environment variable.
- A pointer to an argument vector. The value in argv should represent the filename of the program that you're loading. The last member of argv must be a NULL pointer. The value of argv can't be NULL, and argv can't be a NULL pointer, even if you're not passing any argument strings.
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The spawnvp() function creates and executes a new child process, named in file with the NULL-terminated list of arguments in the argv vector. This function calls spawnvpe().
|If the new process is a shell script, the first line must start with #!, followed by the path and arguments of the shell to be run to interpret the script. The script must also be marked as executable.|
The spawnvp() function isn't a POSIX 1003.1 function, and isn't guaranteed to behave the same on all operating systems. It calls spawnvpe() before calling spawnp().
To view the documentation for a function, click its name in this diagram:
Most of the spawn*() functions do a lot of work before a message is sent to procnto.
The child process inherits the parent's environment. The environment is the collection of environment variables whose values that have been defined with the export shell command, the env utility, or by the successful execution of the putenv() or setenv() function. A program may read these values with the getenv() function.
|A parent/child relationship doesn't imply that the child process dies when the parent process dies.|
The spawnvp() function's return value depends on the mode argument:
|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).
- The number of bytes used by the argument list of the new child process is greater than ARG_MAX bytes.
- Search permission is denied for a directory listed in the path prefix of the new child process or the new child process's file doesn't have the execute bit set.
- Insufficient resources available to create the child process.
- An error occurred duplicating open file descriptors to the new process.
- One of the buffers specified in the function call is invalid.
- Too many levels of symbolic links or prefixes.
- Insufficient resources available to load the new executable image or to remap file descriptors in the child process.
- The length of file and its path exceeds PATH_MAX or a pathname component is longer than NAME_MAX.
- The file identified by the file argument is empty, or one or more components of the pathname of the new process don't exist.
- The child process file has the correct permissions, but isn't in the correct format for an executable.
- Insufficient memory available to create the child process.
- The spawnvp() function isn't implemented for the filesystem specified in file.
- A component of the path prefix of the child process isn't a directory.
|Cancellation point||Read the Caveats|
If mode is P_WAIT, this function is a cancellation point.
execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), getenv(), putenv(), setenv(), spawn(), spawnl(), spawnle(), spawnlp(), spawnlpe(), spawnp(), spawnv(), spawnve(), spawnvpe(), wait(), waitpid()