This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
Create and execute a new child process, given a relative path
#include <spawn.h> pid_t spawnp( const char * file, int fd_count, const int fd_map[ ], const struct inheritance * inherit, char * const argv[ ], char * const envp[ ] );
If you set fdmap[X] to SPAWN_FDCLOSED instead of to a valid file descriptor, the file descriptor X is closed in the child process.
If fd_count is 0, all file descriptors (except for the ones modified with fcntl()'s FD_CLOEXEC flag) are inherited by the child process.
If you want to spawnp() remotely, set the nd member of the inheritance structure to the node descriptor. See the netmgr_strtond() function. |
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.
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The spawnp() function creates and executes a new child process, named in file. It sets the SPAWN_CHECK_SCRIPT and SPAWN_SEARCH_PATH flags, and then calls spawn().
If the new child 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 spawnp() function is a QNX function (based on the POSIX 1003.1d draft standard). The C library also includes several specialized spawn*() functions. Their names consist of spawn followed by several letters:
This suffix: | Indicates the function takes these arguments: |
---|---|
e | An array of environment variables. |
l | A NULL-terminated list of arguments to the program. |
p | A relative path. If the path doesn't contain a slash, the PATH environment variable is searched for the program. This suffix also lets the #! construction work; see SPAWN_CHECK_SCRIPT in the documentation for spawn(). |
v | A vector of arguments to the program. |
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 following attributes of the parent process:
The child process has several differences from the parent process:
If the child process is spawned on a remote node, the process group ID and the session membership aren't set; the child process is put into a new session and a new process group.
The child process can access its environment by using the environ global variable (found in <unistd.h>).
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 child process. Otherwise, if the set-user ID mode bit is set, the effective user ID of the child process is set to the owner ID of file. Similarly, if the set-group ID mode bit is set, the effective group ID of the child process is set to the group ID of file. The real user ID, real group ID and supplementary group IDs of the child process remain the same as those of the parent process. The effective user ID and effective group ID of the child process are saved as the saved set-user ID and the saved set-group ID used by the setuid().
The following arguments are passed to the underlying call (spawn()):
A parent/child relationship doesn't imply that the child process dies when the parent process dies. |
The process ID of the child process, or -1 if an error occurs (errno is set).
If you set SPAWN_EXEC in the flags member of the inheritence structure, spawnp() doesn't return, unless an error occurred. |
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), getenv(), netmgr_strtond(), putenv(), setenv(), sigaddset(), sigdelset(), sigemptyset(), sigfillset(), spawn(), spawnl(), spawnle(), spawnlp(), spawnlpe(), spawnv(), spawnve(), spawnvp(), spawnvpe(), wait(), waitpid()