Home

posixspawn

Posix_spawn is a POSIX standard API for creating new processes. It provides a single, high-level interface to start a program and is designed as a safer and potentially more efficient alternative to the traditional fork followed by exec. The API is implemented on many Unix-like systems and in standard C libraries.

Two forms exist: posix_spawn and posix_spawnp. posix_spawn uses an explicit path to the executable, while posix_spawnp

Prototype (typical C usage):

int posix_spawn(pid_t *restrict pid, const char *restrict path, const posix_spawn_file_actions_t *restrict file_actions, const posix_spawn_attr_t *restrict attrp,

int posix_spawnp(pid_t *restrict pid, const char *restrict file, const posix_spawn_file_actions_t *restrict file_actions, const posix_spawn_attr_t *restrict attrp,

The file_actions and attrp parameters describe actions and attributes for the new process. File actions may

Return values: On success, posix_spawn stores the child process ID in *pid (when pid is non-null) and

Portability and usage: posix_spawn is mandated by POSIX, but actual support varies by system. Some platforms

searches
for
the
executable
on
the
PATH.
char
*const
argv[restrict],
char
*const
envp[restrict]);
char
*const
argv[restrict],
char
*const
envp[restrict]);
specify
duplicating,
opening,
or
closing
file
descriptors;
attributes
may
set
IDs,
scheduling
parameters,
and
other
behavior
at
spawn.
returns
0.
On
failure,
it
returns
a
nonzero
errno
value
and
no
child
process
is
created.
implement
a
comprehensive
set
of
spawn
attributes,
while
others
provide
a
more
limited
subset.
It
is
commonly
used
in
multithreaded
programs
to
avoid
the
race
conditions
associated
with
fork
and
exec.