posix_spawn - spawns a process.
libc.lib
#include <spawn.h> int posix_spawn(pid_t * pid, const char * path, const posix_spawn_file_actions_t *file_actions, const posix_spawnattr_t * attrp, char *const argv[], char *const envp[]);
The posix_spawn created a new child process from the specified process image. A C program executed as a result of this call will be a call to the C-language main function:
int main(int argc,
char *argv[])
The argument argv
is an array of character pointers to null terminated strings. The last member of
this array will be NULL [not counted in
argc]. The
string argv[0]
should point to a filename that is associated with the process image being
started by the posix_spawn()
function. Other strings constitute the
arg list to the new process image.
The argument envp
is an array of character pointers to null terminated strings. This array is
terminated by a NULL pointer. These strings constitute the environment for the
new process image.
The argument path is a pathname that identifies the new process image file to
execute.
If the argument file_actions
is a NULL pointer, then the file descriptors open in the parent process will
remain open in the child process except for those whose
FD_CLOEXEC
[close on exec]
is set [using fcntl].
For the file descriptors that remain open, all the flags of the open file
descriptors will remain unchanged including file locks.
If the argument file_actions
is not NULL, then the file descriptors open in the child process will be those
open in the parent process as modified by the spawn fileactions object pointed
to by file_actions
and the
FD_CLOEXEC flag of each of the remaining open
file descriptor after the spawn file actions have been processed.
The effective order of processing the spawn file actions will be:
1. The set of open file descriptors for the child process will initially be the
same set as is open for the calling process. All attributes of the corresponding
open file descriptions, including file locks, will remain unchanged.
2. The signal mask, signal default actions, and the effective user and group IDs
for the child process will be changed as specified in the attributes object
referenced by attrp.
3. The file actions specified by the spawn file actions object will be performed
in the order in which they were added to the spawn file actions object.
4. Any file descriptor that has its
FD_CLOEXEC flag set will be closed.
The argument attrp
is a pointer to posix_spawnattr_t
spawn attributes defined in spawn.h.
If the value of the attrp
pointer is NULL, then the default values are used.
spawn attributes will contain at least the attributes defined below.
If the POSIX_SPAWN_SETPGROUP
flag is set in the spawn-flags attribute of the
object referenced by attrp,
and the spawn-pgroup
attribute of the same object is non-zero, then the child's process group will be
as specified in the spawn-pgroup
attribute of the object referenced by
attrp. This
attribute is currently ignored.
As a special case, if the
POSIX_SPAWN_SETPGROUP flag is set in the
spawn-flags attribute of the object referenced by
attrp, and
the spawn-pgroup
attribute of the same object is set to zero, then the child will be in a new
process group with a process group ID equal to its process ID. This attribute is
currently ignored.
If the POSIX_SPAWN_SETPGROUP
flag is not set in the spawn-flags attribute of the object referenced by
attrp, the
new child process will inherit the parent's process group. This attribute is
currently ignored.
If the POSIX_SPAWN_SETSCHEDPARAM
flag is set in the spawn-flags attribute of the
object referenced by attrp,
but POSIX_SPAWN_SETSCHEDULER
is not set, the new process image will initially have the scheduling policy of
the calling process with the scheduling parameters specified in the
spawn-schedparam
attribute of the object referenced by
attrp. This attribute is currently ignored.
If the POSIX_SPAWN_SETSCHEDULER
flag is set in the spawn-flags attribute of the
object referenced by attrp
(regardless of the setting of the
POSIX_SPAWN_SETSCHEDPARAM flag), the new
process image will initially have the scheduling policy specified in the
spawn-schedpolicy
attribute of the object referenced by
attrp and
the scheduling parameters specified in the
spawn-schedparam
attribute of the same object. This attribute is currently ignored.
The POSIX_SPAWN_RESETIDS
flag in the spawn-flags attribute of the object referenced by
attrp
governs the effective user ID of the child process. If this flag is not set, the
child process will inherit the parent process' effective user ID. If this flag
is set, the child process' effective user ID will be reset to the parent's real
user ID. In either case, if the set-user-ID mode bit of the new process image
file is set, the effective user ID of the child process will become that file's
owner ID before the new process image begins execution. This attribute is
currently ignored.
The POSIX_SPAWN_RESETIDS
flag in the spawn-flags attribute of the object referenced by
attrp also
governs the effective group ID of the child process. If this flag is not set,
the child process will inherit the parent process' effective group ID. If this
flag is set, the child process' effective group ID will be reset to the parent's
real group ID. In either case, if the set-group-ID mode bit of the new process
image file is set, the effective group ID of the child process will become that
file's group ID before the new process image begins execution. This attribute is
currently ignored.
If the POSIX_SPAWN_SETSIGMASK
flag is set in the spawn-flags attribute of the object referenced by
attrp, the
child process will initially have the signal mask specified in the
spawn-sigmask
attribute of the object referenced by
attrp. This attribute is currently ignored.
If the POSIX_SPAWN_SETSIGDEF
flag is set in the spawn-flags attribute of the object referenced by
attrp, the
signals specified in the spawn-sigdefault
attribute of the same object will be set to their default actions in the child
process. Signals set to the default action in the parent process will be set to
the default action in the child process. This attribute is currently ignored.
On success,
posix_spawn returns 0 and stores the process
ID of the child process in the variable pointed to by the
pid [if
pid
is not NULL]. If no child process is created, the error number that is set is
returned to the caller.
On error, the value stored in the variable pointed to by
pid [if
pid
is not NULL] is unspecified.
The posix_spawn() function may fail if:
[EINVAL]
The value specified by file_actions
or attrp
is invalid.
[ECHILD]
Unable to create the child process.
[EILSEQ]
Unable to convert input strings to their
wchar
variants.
For additional information or queries on this page send feedback
© 2005-2007 Nokia |