1 .\" Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" Portions of this text are reprinted and reproduced in electronic form
26 .\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
27 .\" Portable Operating System Interface (POSIX), The Open Group Base
28 .\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
29 .\" Electrical and Electronics Engineers, Inc and The Open Group. In the
30 .\" event of any discrepancy between this version and the original IEEE and
31 .\" The Open Group Standard, the original IEEE and The Open Group Standard is
32 .\" the referee document. The original Standard can be obtained online at
33 .\" http://www.opengroup.org/unix/online.html.
50 .Fa "pid_t *restrict pid"
51 .Fa "const char *restrict path"
52 .Fa "const posix_spawn_file_actions_t *file_actions"
53 .Fa "const posix_spawnattr_t *restrict attrp"
54 .Fa "char *const argv[restrict]"
55 .Fa "char *const envp[restrict]"
59 .Fa "pid_t *restrict pid"
60 .Fa "const char *restrict file"
61 .Fa "const posix_spawn_file_actions_t *file_actions"
62 .Fa "const posix_spawnattr_t *restrict attrp"
63 .Fa "char *const argv[restrict]"
64 .Fa "char *const envp[restrict]"
71 functions create a new process (child process) from the specified
73 The new process image is constructed from a regular executable
74 file called the new process image file.
76 When a C program is executed as the result of this call, it is
77 entered as a C-language function call as follows:
78 .Bd -literal -offset indent
79 int main(int argc, char *argv[]);
84 is the argument count and
86 is an array of character pointers to the arguments themselves.
87 In addition, the variable:
88 .Bd -literal -offset indent
89 extern char **environ;
92 points to an array of character pointers to
93 the environment strings.
97 is an array of character pointers to null-terminated
99 The last member of this array is a null pointer and is not counted
102 These strings constitute the argument list available to the new process
107 a filename that is associated with the process image being started by
116 is an array of character pointers to null-terminated strings.
117 These strings constitute the environment for the new process image.
118 The environment array is terminated by a null pointer.
124 is a pathname that identifies the new process image file to execute.
130 is used to construct a pathname that identifies the new process
132 If the file parameter contains a slash character, the file parameter
133 is used as the pathname for the new process image file.
134 Otherwise, the path prefix for this file is obtained by a search
135 of the directories passed as the environment variable
137 If this variable is not specified,
138 the default path is set according to the
143 .Dq Ev /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin .
147 is a null pointer, then file descriptors open in the
148 calling process remain open in the child process, except for those
149 whose close-on-exec flag
154 file descriptors that remain open, all attributes of the corresponding
155 open file descriptions, including file locks (see
161 is not NULL, then the file descriptors open in the child process are
162 those open in the calling process as modified by the spawn file
163 actions object pointed to by
167 flag of each remaining open file descriptor after the spawn file actions
169 The effective order of processing the spawn file actions are:
172 The set of open file descriptors for the child process initially
173 are the same set as is open for the calling process.
174 All attributes of the corresponding open file descriptions, including
179 The signal mask, signal default actions, and the effective user and
180 group IDs for the child process are changed as specified in the
181 attributes object referenced by
184 The file actions specified by the spawn file actions object are
185 performed in the order in which they were added to the spawn file
188 Any file descriptor that has its
196 .Vt posix_spawnattr_t
197 spawn attributes object type is defined in
199 It contains the attributes defined below.
202 .Dv POSIX_SPAWN_SETPGROUP
203 flag is set in the spawn-flags attribute of the object referenced by
205 and the spawn-pgroup attribute of the same object is non-zero, then the
206 child's process group is as specified in the spawn-pgroup
207 attribute of the object referenced by
210 As a special case, if the
211 .Dv POSIX_SPAWN_SETPGROUP
212 flag is set in the spawn-flags attribute of the object referenced by
214 and the spawn-pgroup attribute of the same object is set to zero, then
215 the child is in a new process group with a process group ID equal
219 .Dv POSIX_SPAWN_SETPGROUP
220 flag is not set in the spawn-flags attribute of the object referenced by
222 the new child process inherits the parent's process group.
225 .Dv POSIX_SPAWN_SETSCHEDPARAM
226 flag is set in the spawn-flags attribute of the object referenced by
229 .Dv POSIX_SPAWN_SETSCHEDULER
230 is not set, the new process image initially has the scheduling
231 policy of the calling process with the scheduling parameters specified
232 in the spawn-schedparam attribute of the object referenced by
236 .Dv POSIX_SPAWN_SETSCHEDULER
237 flag is set in the spawn-flags attribute of the object referenced by
239 (regardless of the setting of the
240 .Dv POSIX_SPAWN_SETSCHEDPARAM
241 flag), the new process image initially has the scheduling policy
242 specified in the spawn-schedpolicy attribute of the object referenced by
244 and the scheduling parameters specified in the spawn-schedparam
245 attribute of the same object.
248 .Dv POSIX_SPAWN_RESETIDS
249 flag in the spawn-flags attribute of the object referenced by
251 governs the effective user ID of the child process.
252 If this flag is not set, the child process inherits the parent
253 process' effective user ID.
254 If this flag is set, the child process' effective user ID is reset
255 to the parent's real user ID.
256 In either case, if the set-user-ID mode bit of the new process image
257 file is set, the effective user ID of the child process becomes
258 that file's owner ID before the new process image begins execution.
261 .Dv POSIX_SPAWN_RESETIDS
262 flag in the spawn-flags attribute of the object referenced by
264 also governs the effective group ID of the child process.
265 If this flag is not set, the child process inherits the parent
266 process' effective group ID.
267 If this flag is set, the child process' effective group ID is
268 reset to the parent's real group ID.
269 In either case, if the set-group-ID mode bit of the new process image
270 file is set, the effective group ID of the child process becomes
271 that file's group ID before the new process image begins execution.
274 .Dv POSIX_SPAWN_SETSIGMASK
275 flag is set in the spawn-flags attribute of the object referenced by
277 the child process initially has the signal mask specified in the
278 spawn-sigmask attribute of the object referenced by
282 .Dv POSIX_SPAWN_SETSIGDEF
283 flag is set in the spawn-flags attribute of the object referenced by
285 the signals specified in the spawn-sigdefault attribute of the same
286 object are set to their default actions in the child process.
287 Signals set to the default action in the parent process are set to
288 the default action in the child process.
290 Signals set to be caught by the calling process are set to the
291 default action in the child process.
293 Signals set to be ignored by the calling process image are set to
294 be ignored by the child process, unless otherwise specified by the
295 .Dv POSIX_SPAWN_SETSIGDEF
296 flag being set in the spawn-flags attribute of the object referenced by
298 and the signals being indicated in the spawn-sigdefault attribute
299 of the object referenced by
304 pointer is NULL, then the default values are used.
306 All process attributes, other than those influenced by the attributes
307 set in the object referenced by
309 as specified above or by the file descriptor manipulations specified in
311 appear in the new process image as though
313 had been called to create a child process and then
315 had been called by the child process to execute the new process image.
317 The implementation uses
319 thus the fork handlers are not run when
325 Upon successful completion,
329 return the process ID of the child process to the parent process,
330 in the variable pointed to by a non-NULL
332 argument, and return zero as the function return value.
333 Otherwise, no child process is created, no value is stored into
334 the variable pointed to by
336 and an error number is returned as the function return value to
340 argument is a null pointer, the process ID of the child is not returned
349 fail for any of the reasons that would cause
353 to fail, an error value is returned as described by
357 respectively (or, if the error occurs after the calling process successfully
358 returns, the child process exits with exit status 127).
361 .Nm POSIX_SPAWN_SETPGROUP
362 is set in the spawn-flags attribute of the object referenced by attrp, and
366 fails while changing the child's process group, an error value is returned as
369 (or, if the error occurs after the calling process successfully returns,
370 the child process exits with exit status 127).
373 .Nm POSIX_SPAWN_SETSCHEDPARAM
375 .Nm POSIX_SPAWN_SETSCHEDULER
376 is not set in the spawn-flags attribute of the object referenced by attrp, then
381 fails for any of the reasons that would cause
383 to fail, an error value is returned as described by
385 (or, if the error occurs after the calling process successfully returns, the
386 child process exits with exit status 127).
389 .Nm POSIX_SPAWN_SETSCHEDULER
390 is set in the spawn-flags attribute of the object referenced by attrp, and if
394 fails for any of the reasons that would cause
395 .Fn sched_setscheduler
396 to fail, an error value is returned as described by
397 .Fn sched_setscheduler
398 (or, if the error occurs after the calling process successfully returns,
399 the child process exits with exit status 127).
403 argument is not NULL, and specifies any dup2 or open actions to be
408 fails for any of the reasons that would cause
412 to fail, an error value is returned as described by
416 respectively (or, if the error occurs after the calling process successfully
417 returns, the child process exits with exit status 127). An open file action
418 may, by itself, result in any of the errors described by
420 in addition to those described by
422 This implementation ignores any errors from
424 including trying to close a descriptor that is not open.
425 The ignore extends to any errors from individual file descriptors
427 executed as part of the
437 .Xr sched_setparam 2 ,
438 .Xr sched_setscheduler 2 ,
441 .Xr posix_spawn_file_actions_addclose 3 ,
442 .Xr posix_spawn_file_actions_addclosefrom_np 3 ,
443 .Xr posix_spawn_file_actions_adddup2 3 ,
444 .Xr posix_spawn_file_actions_addopen 3 ,
445 .Xr posix_spawn_file_actions_addchdir_np 3 ,
446 .Xr posix_spawn_file_actions_addfchdir_np 3 ,
447 .Xr posix_spawn_file_actions_destroy 3 ,
448 .Xr posix_spawn_file_actions_init 3 ,
449 .Xr posix_spawnattr_destroy 3 ,
450 .Xr posix_spawnattr_getflags 3 ,
451 .Xr posix_spawnattr_getpgroup 3 ,
452 .Xr posix_spawnattr_getschedparam 3 ,
453 .Xr posix_spawnattr_getschedpolicy 3 ,
454 .Xr posix_spawnattr_getsigdefault 3 ,
455 .Xr posix_spawnattr_getsigmask 3 ,
456 .Xr posix_spawnattr_init 3 ,
457 .Xr posix_spawnattr_setflags 3 ,
458 .Xr posix_spawnattr_setpgroup 3 ,
459 .Xr posix_spawnattr_setschedparam 3 ,
460 .Xr posix_spawnattr_setschedpolicy 3 ,
461 .Xr posix_spawnattr_setsigdefault 3 ,
462 .Xr posix_spawnattr_setsigmask 3
470 except that they ignore all errors from
472 A future update of the Standard is expected to require that these functions
473 not fail because a file descriptor to be closed (via
474 .Fn posix_spawn_file_actions_addclose )
481 functions first appeared in
484 .An \&Ed Schouten Aq Mt ed@FreeBSD.org