1 .\" $NetBSD: posix_spawn.3,v 1.6 2014/02/02 16:59:06 wiz Exp $
3 .\" Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" Portions of this text are reprinted and reproduced in electronic form
28 .\" from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology --
29 .\" Portable Operating System Interface (POSIX), The Open Group Base
30 .\" Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of
31 .\" Electrical and Electronics Engineers, Inc and The Open Group. In the
32 .\" event of any discrepancy between this version and the original IEEE and
33 .\" The Open Group Standard, the original IEEE and The Open Group Standard is
34 .\" the referee document. The original Standard can be obtained online at
35 .\" http://www.opengroup.org/unix/online.html.
37 .\" $FreeBSD: src/lib/libc/gen/posix_spawn.3,v 1.2.2.1.4.1 2010/06/14 02:09:06 kensmith Exp $
51 .Fn posix_spawn "pid_t *restrict pid" "const char *restrict path" "const posix_spawn_file_actions_t *file_actions" "const posix_spawnattr_t *restrict attrp" "char *const argv[restrict]" "char *const envp[restrict]"
53 .Fn posix_spawnp "pid_t *restrict pid" "const char *restrict file" "const posix_spawn_file_actions_t *file_actions" "const posix_spawnattr_t *restrict attrp" "char *const argv[restrict]" "char *const envp[restrict]"
59 functions create a new process (child process) from the specified
61 The new process image is constructed from a regular executable
62 file called the new process image file.
64 When a C program is executed as the result of this call, it is
65 entered as a C-language function call as follows:
66 .Bd -literal -offset indent
67 int main(int argc, char *argv[]);
72 is the argument count and
74 is an array of character pointers to the arguments themselves.
75 In addition, the variable:
76 .Bd -literal -offset indent
77 extern char **environ;
80 points to an array of character pointers to
81 the environment strings.
85 is an array of character pointers to null-terminated
87 The last member of this array is a null pointer and is not counted
90 These strings constitute the argument list available to the new process
95 a filename that is associated with the process image being started by
104 is an array of character pointers to null-terminated strings.
105 These strings constitute the environment for the new process image.
106 The environment array is terminated by a null pointer.
112 is a pathname that identifies the new process image file to execute.
118 is used to construct a pathname that identifies the new process
120 If the file parameter contains a slash character, the file parameter
121 is used as the pathname for the new process image file.
122 Otherwise, the path prefix for this file is obtained by a search
123 of the directories passed as the environment variable
125 If this variable is not specified,
126 the default path is set according to the
131 .Dq Ev /usr/bin:/bin .
135 is a null pointer, then file descriptors open in the
136 calling process remain open in the child process, except for those
137 whose close-on-exec flag
142 file descriptors that remain open, all attributes of the corresponding
143 open file descriptions, including file locks (see
151 then the file descriptors open in the child process are
152 those open in the calling process as modified by the spawn file
153 actions object pointed to by
157 flag of each remaining open file descriptor after the spawn file actions
159 The effective order of processing the spawn file actions are:
162 The set of open file descriptors for the child process initially
163 are the same set as is open for the calling process.
164 All attributes of the corresponding open file descriptions, including
169 The signal mask, signal default actions, and the effective user and
170 group IDs for the child process are changed as specified in the
171 attributes object referenced by
174 The file actions specified by the spawn file actions object are
175 performed in the order in which they were added to the spawn file
178 Any file descriptor that has its
185 The maximum number of
187 objects is limited to the
192 .Vt posix_spawnattr_t
193 spawn attributes object type is defined in
195 It contains the attributes defined below.
198 .Dv POSIX_SPAWN_SETPGROUP
199 flag is set in the spawn-flags attribute of the object referenced by
201 and the spawn-pgroup attribute of the same object is non-zero, then the
202 child's process group is as specified in the spawn-pgroup
203 attribute of the object referenced by
206 As a special case, if the
207 .Dv POSIX_SPAWN_SETPGROUP
208 flag is set in the spawn-flags attribute of the object referenced by
210 and the spawn-pgroup attribute of the same object is set to zero, then
211 the child is in a new process group with a process group ID equal
215 .Dv POSIX_SPAWN_SETPGROUP
216 flag is not set in the spawn-flags attribute of the object referenced by
218 the new child process inherits the parent's process group.
221 .Dv POSIX_SPAWN_SETSCHEDPARAM
222 flag is set in the spawn-flags attribute of the object referenced by
225 .Dv POSIX_SPAWN_SETSCHEDULER
226 is not set, the new process image initially has the scheduling
227 policy of the calling process with the scheduling parameters specified
228 in the spawn-schedparam attribute of the object referenced by
232 .Dv POSIX_SPAWN_SETSCHEDULER
233 flag is set in the spawn-flags attribute of the object referenced by
235 (regardless of the setting of the
236 .Dv POSIX_SPAWN_SETSCHEDPARAM
237 flag), the new process image initially has the scheduling policy
238 specified in the spawn-schedpolicy attribute of the object referenced by
240 and the scheduling parameters specified in the spawn-schedparam
241 attribute of the same object.
244 .Dv POSIX_SPAWN_RESETIDS
245 flag in the spawn-flags attribute of the object referenced by
247 governs the effective user ID of the child process.
248 If this flag is not set, the child process inherits the parent
249 process' effective user ID.
250 If this flag is set, the child process' effective user ID is reset
251 to the parent's real user ID.
252 In either case, if the set-user-ID mode bit of the new process image
253 file is set, the effective user ID of the child process becomes
254 that file's owner ID before the new process image begins execution.
257 .Dv POSIX_SPAWN_RESETIDS
258 flag in the spawn-flags attribute of the object referenced by
260 also governs the effective group ID of the child process.
261 If this flag is not set, the child process inherits the parent
262 process' effective group ID.
263 If this flag is set, the child process' effective group ID is
264 reset to the parent's real group ID.
265 In either case, if the set-group-ID mode bit of the new process image
266 file is set, the effective group ID of the child process becomes
267 that file's group ID before the new process image begins execution.
270 .Dv POSIX_SPAWN_SETSIGMASK
271 flag is set in the spawn-flags attribute of the object referenced by
273 the child process initially has the signal mask specified in the
274 spawn-sigmask attribute of the object referenced by
278 .Dv POSIX_SPAWN_SETSIGDEF
279 flag is set in the spawn-flags attribute of the object referenced by
281 the signals specified in the spawn-sigdefault attribute of the same
282 object is set to their default actions in the child process.
283 Signals set to the default action in the parent process is set to
284 the default action in the child process.
286 Signals set to be caught by the calling process is set to the
287 default action in the child process.
289 Signals set to be ignored by the calling process image is set to
290 be ignored by the child process, unless otherwise specified by the
291 .Dv POSIX_SPAWN_SETSIGDEF
292 flag being set in the spawn-flags attribute of the object referenced by
294 and the signals being indicated in the spawn-sigdefault attribute
295 of the object referenced by
302 then the default values are used.
304 All process attributes, other than those influenced by the attributes
305 set in the object referenced by
307 as specified above or by the file descriptor manipulations specified in
309 appear in the new process image as though
311 had been called to create a child process and then
313 had been called by the child process to execute the new process image.
315 The implementation uses vfork(), thus the fork handlers are not run when
321 Upon successful completion,
325 return the process ID of the child process to the parent process,
326 in the variable pointed to by a
329 argument, and return zero as the function return value.
330 Otherwise, no child process is created, no value is stored into
331 the variable pointed to by
333 and an error number is returned as the function return value to
337 argument is a null pointer, the process ID of the child is not returned
346 fail for any of the reasons that would cause
350 to fail, an error value is returned as described by
354 respectively (or, if the error occurs after the calling process successfully
355 returns, the child process exits with exit status 127).
358 .Nm POSIX_SPAWN_SETPGROUP
359 is set in the spawn-flags attribute of the object referenced by attrp, and
363 fails while changing the child's process group, an error value is returned as
366 (or, if the error occurs after the calling process successfully returns,
367 the child process exits with exit status 127).
370 .Nm POSIX_SPAWN_SETSCHEDPARAM
372 .Nm POSIX_SPAWN_SETSCHEDULER
373 is not set in the spawn-flags attribute of the object referenced by attrp, then
378 fails for any of the reasons that would cause
380 to fail, an error value is returned as described by
382 (or, if the error occurs after the calling process successfully returns, the
383 child process exits with exit status 127).
386 .Nm POSIX_SPAWN_SETSCHEDULER
387 is set in the spawn-flags attribute of the object referenced by attrp, and if
391 fails for any of the reasons that would cause
392 .Fn sched_setscheduler
393 to fail, an error value is returned as described by
394 .Fn sched_setscheduler
395 (or, if the error occurs after the calling process successfully returns,
396 the child process exits with exit status 127).
407 actions to be performed, and if
411 fails for any of the reasons that would cause
416 to fail, an error value is returned as described by
421 respectively (or, if the error occurs after the calling process successfully
422 returns, the child process exits with exit status 127). An open file action
423 may, by itself, result in any of the errors described by
427 in addition to those described by
429 Finally, if the number of
431 objects exceeds the allowed limit,
443 .Xr posix_spawn_file_actions_addclose 3 ,
444 .Xr posix_spawn_file_actions_adddup2 3 ,
445 .Xr posix_spawn_file_actions_addopen 3 ,
446 .Xr posix_spawn_file_actions_destroy 3 ,
447 .Xr posix_spawn_file_actions_init 3 ,
448 .Xr posix_spawnattr_destroy 3 ,
449 .Xr posix_spawnattr_getflags 3 ,
450 .Xr posix_spawnattr_getpgroup 3 ,
451 .Xr posix_spawnattr_getschedparam 3 ,
452 .Xr posix_spawnattr_getschedpolicy 3 ,
453 .Xr posix_spawnattr_getsigdefault 3 ,
454 .Xr posix_spawnattr_getsigmask 3 ,
455 .Xr posix_spawnattr_init 3 ,
456 .Xr posix_spawnattr_setflags 3 ,
457 .Xr posix_spawnattr_setpgroup 3 ,
458 .Xr posix_spawnattr_setschedparam 3 ,
459 .Xr posix_spawnattr_setschedpolicy 3 ,
460 .Xr posix_spawnattr_setsigdefault 3 ,
461 .Xr posix_spawnattr_setsigmask 3 ,
462 .Xr sched_setparam 3 ,
463 .Xr sched_setscheduler 3
476 functions first appeared in
478 The library parts were ported and a kernel implementation of
482 during Google Summer of Code by Charles Zhang and Martin Husemann.
484 .An Ed Schouten Aq Mt ed@FreeBSD.org