1502 Remove conversion cruft from manpages
[unleashed.git] / usr / src / man / man3c / posix_spawn.3c
blob44407e68e94579449f125daa4db64ef8269729d5
1 '\" te
2 .\" Copyright (c) 2001, the Institute of Electrical and Electronics Engineers, Inc. and The Open Group. All Rights Reserved.
3 .\" Portions Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at  http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
6 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
7 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH POSIX_SPAWN 3C "Feb 20, 2009"
13 .SH NAME
14 posix_spawn, posix_spawnp \- spawn a process
15 .SH SYNOPSIS
16 .LP
17 .nf
18 #include <spawn.h>
20 \fBint\fR \fBposix_spawn\fR(\fBpid_t *restrict\fR \fIpid\fR, \fBconst char *restrict\fR \fIpath\fR,
21      \fBconst posix_spawn_file_actions_t *\fR\fIfile_actions\fR,
22      \fBconst posix_spawnattr_t *restrict\fR \fIattrp\fR,
23      \fBchar *const\fR \fIargv\fR[restrict], \fBchar *const\fR \fIenvp\fR[restrict]);
24 .fi
26 .LP
27 .nf
28 \fBint\fR \fBposix_spawnp\fR(\fBpid_t *restrict\fR \fIpid\fR, \fBconst char *restrict\fR \fIfile\fR,
29      \fBconst posix_spawn_file_actions_t *\fR\fIfile_actions\fR,
30      \fBconst posix_spawnattr_t *restrict\fR \fIattrp\fR,
31      \fBchar *const\fR \fIargv\fR[restrict], \fBchar *const\fR \fIenvp\fR[restrict]);
32 .fi
34 .SH DESCRIPTION
35 .sp
36 .LP
37 The \fBposix_spawn()\fR and \fBposix_spawnp()\fR functions create a new process
38 (child process) from the specified process image. The new process image is
39 constructed from a regular executable file called the new process image file.
40 .sp
41 .LP
42 When a C program is executed as the result of this call, it is entered as a C
43 language function call as follows:
44 .sp
45 .in +2
46 .nf
47 int main(int \fIargc\fR, char *\fIargv\fR[]);
48 .fi
49 .in -2
51 .sp
52 .LP
53 where \fIargc\fR is the argument count and \fIargv\fR is an array of character
54 pointers to the arguments themselves. In addition, the following variable
55 .sp
56 .in +2
57 .nf
58 extern char **environ;
59 .fi
60 .in -2
62 .sp
63 .LP
64 is initialized as a pointer to an array of character pointers to the
65 environment strings.
66 .sp
67 .LP
68 The argument \fIargv\fR is an array of character pointers to null-terminated
69 strings. The last member of this array is a null pointer and is not counted in
70 \fIargc\fR. These strings constitute the argument list available to the new
71 process image. The value in \fIargv\fR[0] should point to a filename that is
72 associated with the process image being started by the \fBposix_spawn()\fR or
73 \fBposix_spawnp()\fR function.
74 .sp
75 .LP
76 The argument \fIenvp\fR is an array of character pointers to null-terminated
77 strings. These strings constitute the environment for the new process image.
78 The environment array is terminated by a null pointer.
79 .sp
80 .LP
81 The number of bytes available for the child process's combined argument and
82 environment lists is {\fBARG_MAX\fR}, counting all character pointers, the
83 strings they point to, the trailing null bytes in the strings, and the
84 list-terminating null pointers. There is no additional system overhead included
85 in this total.
86 .sp
87 .LP
88 The \fIpath\fR argument to \fBposix_spawn()\fR is a pathname that identifies
89 the new process image file to execute.
90 .sp
91 .LP
92 The \fIfile\fR parameter to \fBposix_spawnp()\fR is used to construct a
93 pathname that identifies the new process image file. If the file parameter
94 contains a slash character, the file parameter is used as the pathname for the
95 new process image file. Otherwise, the path prefix for this file is obtained by
96 a search of the directories passed as the environment variable \fBPATH\fR. If
97 this environment variable is not defined, the results of the search are
98 implementation-defined.
99 .sp
101 If \fIfile_actions\fR is a null pointer, then file descriptors open in the
102 calling process remain open in the child process, except for those whose
103 close-on-exec flag \fBFD_CLOEXEC\fR is set (see \fBfcntl\fR(2)).  For those
104 file descriptors that remain open, all attributes of the corresponding open
105 file descriptions, including file locks (see \fBfcntl\fR(2)), remain unchanged.
108 If \fIfile_actions\fR is not \fINULL\fR, then the file descriptors open in the
109 child process are those open in the calling process as modified by the spawn
110 file actions object pointed to by \fIfile_actions\fR and the \fBFD_CLOEXEC\fR
111 flag of each remaining open file descriptor after the spawn file actions have
112 been processed. The effective order of processing the spawn file actions are:
113 .RS +4
116 The set of open file descriptors for the child process are initially the
117 same set as is open for the calling process. All attributes of the
118 corresponding open file descriptions, including file locks (see
119 \fBfcntl\fR(2)), remain unchanged.
121 .RS +4
124 The signal mask, signal default or ignore actions, and the effective user
125 and group IDs for the child process are changed as specified in the attributes
126 object referenced by \fIattrp\fR.
128 .RS +4
131 The file actions specified by the spawn file actions object are performed in
132 the order in which they were added to the spawn file actions object.
134 .RS +4
137 Any file descriptor that has its \fBFD_CLOEXEC\fR flag set (see
138 \fBfcntl\fR(2)) is closed.
142 The \fBposix_spawnattr_t\fR spawn attributes object type is defined in
143 <\fBspawn.h\fR>. It contains at least the attributes defined below.
146 If the \fBPOSIX_SPAWN_SETPGROUP\fR flag is set in the \fIspawn-flags\fR
147 attribute of the object referenced by \fIattrp\fR, and the \fIspawn-pgroup\fR
148 attribute of the same object is non-zero, then the child's process group is as
149 specified in the \fIspawn-pgroup\fR attribute of the object referenced by
150 \fIattrp\fR.
153 As a special case, if the \fBPOSIX_SPAWN_SETPGROUP\fR flag is set in the
154 \fIspawn-flags\fR attribute of the object referenced by \fIattrp\fR, and the
155 \fIspawn-pgroup\fR attribute of the same object is set to zero, then the child
156 will be in a new process group with a process group ID equal to its process ID.
159 If the \fBPOSIX_SPAWN_SETPGROUP\fR flag is not set in the \fIspawn-flags\fR
160 attribute of the object referenced by \fIattrp\fR, the new child process
161 inherits the parent's process group.
164 If the \fBPOSIX_SPAWN_SETSCHEDPARAM\fR flag is set in the \fIspawn-flags\fR
165 attribute of the object referenced by \fIattrp\fR, but
166 \fBPOSIX_SPAWN_SETSCHEDULER\fR is not set, the new process image initially has
167 the scheduling policy of the calling process with the scheduling parameters
168 specified in the \fIspawn-schedparam\fR attribute of the object referenced by
169 \fIattrp\fR.
172 If the \fBPOSIX_SPAWN_SETSCHEDULER\fR flag is set in \fIspawn-flags\fR
173 attribute of the object referenced by \fIattrp\fR (regardless of the setting of
174 the \fBPOSIX_SPAWN_SETSCHEDPARAM\fR flag), the new process image initially has
175 the scheduling policy specified in the \fIspawn-schedpolicy\fR attribute of the
176 object referenced by \fIattrp\fR and the scheduling parameters specified in the
177 \fIspawn-schedparam\fR attribute of the same object.
180 The \fBPOSIX_SPAWN_RESETIDS\fR flag in the \fIspawn-flags\fR attribute of the
181 object referenced by \fIattrp\fR governs the effective user ID of the child
182 process. If this flag is not set, the child process inherits the parent
183 process's effective user ID. If this flag is set, the child process's effective
184 user ID is reset to the parent's real user ID. In either case, if the
185 set-user-ID mode bit of the new process image file is set, the effective user
186 ID of the child process becomes that file's owner ID before the new process
187 image begins execution. If this flag is set, the child process's effective user
188 ID is reset to the parent's real user ID. In either case, if the set-user-ID
189 mode bit of the new process image file is set, the effective user ID of the
190 child process becomes that file's owner ID before the new process image begins
191 execution.
194 The \fBPOSIX_SPAWN_RESETIDS\fR flag in the \fIspawn-flags\fR attribute of the
195 object referenced by \fIattrp\fR also governs the effective group ID of the
196 child process. If this flag is not set, the child process inherits the parent
197 process's effective group ID. If this flag is set, the child process's
198 effective group ID is reset to the parent's real group ID. In either case, if
199 the set-group-ID mode bit of the new process image file is set, the effective
200 group ID of the child process becomes that file's group ID before the new
201 process image begins execution.
204 If the \fBPOSIX_SPAWN_SETSIGMASK\fR flag is set in the \fIspawn-flags\fR
205 attribute of the object referenced by \fIattrp\fR, the child process initially
206 has the signal mask specified in the \fIspawn-sigmask\fR attribute of the
207 object referenced by \fIattrp\fR.
210 If the \fBPOSIX_SPAWN_SETSIGDEF\fR flag is set in the \fIspawn-flags\fR
211 attribute of the object referenced by \fIattrp\fR, the signals specified in the
212 \fIspawn-sigdefault\fR attribute of the same object is set to their default
213 actions in the child process.
216 If the \fBPOSIX_SPAWN_SETSIGIGN_NP\fR flag is set in the spawn-flags attribute
217 of the object referenced by \fIattrp\fR, the signals specified in the
218 \fIspawn-sigignore\fR attribute of the same object are set to be ignored in the
219 child process.
222 If both \fBPOSIX_SPAWN_SETSIGDEF\fR and \fBPOSIX_SPAWN_SETSIGIGN_NP\fR flags
223 are set in the spawn-flags attribute of the object referenced by \fIattrp\fR,
224 the actions for \fBPOSIX_SPAWN_SETSIGDEF\fR take precedence over the actions
225 for \fBPOSIX_SPAWN_SETSIGIGN_NP\fR.
228 If the \fBPOSIX_SPAWN_NOSIGCHLD_NP\fR flag is set in the \fIspawn-flags\fR
229 attribute of the object referenced by \fIattrp\fR, no \fBSIGCHLD\fR signal will
230 be posted to the parent process when the child process terminates, regardless
231 of the disposition of the \fBSIGCHLD\fR signal in the parent.  \fBSIGCHLD\fR
232 signals are still possible for job control stop and continue actions if the
233 parent has requested them.
236 If the \fBPOSIX_SPAWN_WAITPID_NP\fR flag is set in the \fIspawn-flags\fR
237 attribute of the object referenced by \fIattrp\fR, no wait-for-multiple-pids
238 operation by the parent, as in \fBwait()\fR, \fBwaitid\fR(\fBP_ALL\fR), or
239 \fBwaitid\fR(\fBP_PGID\fR), will succeed in reaping the child, and the child
240 will not be reaped automatically due the disposition of the \fBSIGCHLD\fR
241 signal being set to be ignored in the parent.  Only a specific wait for the
242 child, as in \fBwaitid\fR(\fBP_PID\fR, \fBpid\fR), is allowed and it is
243 required, else when the child exits it will remain a zombie until the parent
244 exits.
247 If the \fBPOSIX_SPAWN_NOEXECERR_NP\fR flag is set in the spawn-flags attribute
248 of the object referenced by \fIattrp\fR, and if the specified process image
249 file cannot be executed, then the \fBposix_spawn()\fR and \fBposix_spawnp()\fR
250 functions do not fail with one of the \fBexec\fR(2) error codes, as is normal,
251 but rather return successfully having created a child process that exits
252 immediately with exit status 127. This flag permits \fBsystem\fR(3C) and
253 \fBpopen\fR(3C) to be implemented with \fBposix_spawn()\fR and still conform
254 strictly to their POSIX specifications.
257 Signals set to be caught or set to the default action in the calling process
258 are set to the default action in the child process, unless the
259 \fBPOSIX_SPAWN_SETSIGIGN_NP\fR flag is set in the spawn-flags attribute of the
260 object referenced by \fIattrp\fR and the signals are specified in the
261 \fIspawn-sigignore\fR attribute of the same object.
264 Except for \fBSIGCHLD\fR, signals set to be ignored by the calling process
265 image are set to be ignored by the child process, unless otherwise specified by
266 the \fBPOSIX_SPAWN_SETSIGDEF\fR flag being set in the \fIspawn-flags\fR
267 attribute of the object referenced by \fIattrp\fR and the signals being
268 indicated in the \fIspawn-sigdefault\fR attribute of the object referenced by
269 \fIattrp\fR.
272 If the \fBSIGCHLD\fR signal is set to be ignored by the calling process, it is
273 unspecified whether the \fBSIGCHLD\fR signal is set to be ignored or to the
274 default action in the child process, unless otherwise specified by the
275 \fBPOSIX_SPAWN_SETSIGDEF\fR flag being set in the \fIspawn-flags\fR attribute
276 of the object referenced by \fIattrp\fR and the \fBSIGCHLD\fR signal being
277 indicated in the \fIspawn-sigdefault\fR attribute of the object referenced by
278 \fIattrp\fR.
281 If the value of the \fIattrp\fR pointer is \fINULL\fR, then the default values
282 are used.
285 All process attributes, other than those influenced by the attributes set in
286 the object referenced by \fIattrp\fR as specified above or by the file
287 descriptor manipulations specified in \fIfile_actions\fR appear in the new
288 process image as though \fBfork()\fR had been called to create a child process
289 and then a member of the \fBexec\fR family of functions had been called by the
290 child process to execute the new process image.
293 The fork handlers are not run when \fBposix_spawn()\fR or \fBposix_spawnp()\fR
294 is called.
295 .SH RETURN VALUES
298 Upon successful completion, \fBposix_spawn()\fR and \fBposix_spawnp()\fR return
299 the process ID of the child process to the parent process in the variable
300 pointed to by a non-null \fIpid\fR argument, and return zero as the function
301 return value. Otherwise, no child process is created, the value stored into the
302 variable pointed to by a non-null \fIpid\fR is unspecified, and an error number
303 is returned as the function return value to indicate the error. If the
304 \fIpid\fR argument is a null pointer, the process ID of the child is not
305 returned to the caller.
306 .SH ERRORS
309 The \fBposix_spawn()\fR and \fBposix_spawnp()\fR functions will fail if:
311 .ne 2
313 \fB\fBEINVAL\fR\fR
315 .RS 10n
316 The value specified by \fIfile_actions\fR or \fIattrp\fR is invalid.
321 If \fBposix_spawn()\fR or \fBposix_spawnp()\fR fails for any of the reasons
322 that would cause \fBfork()\fR or one of the \fBexec\fR family of functions to
323 fail, an error value is returned as described by \fBfork\fR(2) and
324 \fBexec\fR(2), respectively
327 If \fBPOSIX_SPAWN_SETPGROUP\fR is set in the \fIspawn-flags\fR attribute of the
328 object referenced by \fIattrp\fR, and \fBposix_spawn()\fR or
329 \fBposix_spawnp()\fR fails while changing the child's process group, an error
330 value is returned as described by \fBsetpgid\fR(2).
333 If \fBPOSIX_SPAWN_SETSCHEDPARAM\fR is set and \fBPOSIX_SPAWN_SETSCHEDULER\fR is
334 not set in the \fIspawn-flags\fR attribute of the object referenced by
335 \fIattrp\fR, then if \fBposix_spawn()\fR or \fBposix_spawnp()\fR fails for any
336 of the reasons that would cause \fBsched_setparam()\fR to fail, an error value
337 is returned as described by \fBsched_setparam\fR(3C).
340 If \fBPOSIX_SPAWN_SETSCHEDULER\fR is set in the \fIspawn-flags\fR attribute of
341 the object referenced by \fIattrp\fR, and if \fBposix_spawn()\fR or
342 \fBposix_spawnp()\fR fails for any of the reasons that would cause
343 \fBsched_setscheduler()\fR to fail, an error value is returned as described by
344 \fBsched_setscheduler\fR(3C).
347 If the \fIfile_actions\fR argument is not \fINULL\fR and specifies any
348 \fBclose()\fR, \fBdup2()\fR, or \fBopen()\fR actions to be performed, and if
349 \fBposix_spawn()\fR or \fBposix_spawnp()\fR fails for any of the reasons that
350 would cause \fBclose()\fR, \fBdup2()\fR, or \fBopen()\fR to fail, an error
351 value is returned as described by \fBclose\fR(2), \fBdup2\fR(3C), or
352 \fBopen\fR(2), respectively. An open file action might, by itself, result in
353 any of the errors described by \fBclose()\fR or \fBdup2()\fR, in addition to
354 those described by \fBopen()\fR.
357 If a \fBclose\fR(2) operation is specified to be performed for a file
358 descriptor that is not open at the time of the call to \fBposix_spawn()\fR or
359 \fBposix_spawnp()\fR, the action does not cause \fBposix_spawn()\fR or
360 \fBposix_spawnp()\fR to fail.
361 .SH ATTRIBUTES
364 See \fBattributes\fR(5) for descriptions of the following attributes:
369 box;
370 c | c
371 l | l .
372 ATTRIBUTE TYPE  ATTRIBUTE VALUE
374 Interface Stability     Committed
376 MT-Level        MT-Safe
378 Standard        See \fBstandards\fR(5).
381 .SH SEE ALSO
384 \fBalarm\fR(2), \fBchmod\fR(2), \fBclose\fR(2), \fBdup\fR(2), \fBexec\fR(2),
385 \fBexit\fR(2), \fBfcntl\fR(2), \fBfork\fR(2), \fBkill\fR(2), \fBopen\fR(2),
386 \fBsetpgid\fR(2), \fBsetuid\fR(2), \fBstat\fR(2), \fBtimes\fR(2),
387 \fBdup2\fR(3C), \fBpopen\fR(3C), \fBposix_spawn_file_actions_addclose\fR(3C),
388 \fBposix_spawn_file_actions_adddup2\fR(3C),
389 \fBposix_spawn_file_actions_addopen\fR(3C),
390 \fBposix_spawn_file_actions_destroy\fR(3C),
391 \fBposix_spawn_file_actions_init\fR(3C), \fBposix_spawnattr_destroy\fR(3C),
392 \fBposix_spawnattr_getflags\fR(3C), \fBposix_spawnattr_getpgroup\fR(3C),
393 \fBposix_spawnattr_getschedparam\fR(3C),
394 \fBposix_spawnattr_getschedpolicy\fR(3C),
395 \fBposix_spawnattr_getsigdefault\fR(3C),
396 \fBposix_spawnattr_getsigignore_np\fR(3C),
397 \fBposix_spawnattr_getsigmask\fR(3C), \fBposix_spawnattr_init\fR(3C),
398 \fBposix_spawnattr_setflags\fR(3C), \fBposix_spawnattr_setpgroup\fR(3C),
399 \fBposix_spawnattr_setschedparam\fR(3C),
400 \fBposix_spawnattr_setschedpolicy\fR(3C),
401 \fBposix_spawnattr_setsigdefault\fR(3C),
402 \fBposix_spawnattr_setsigignore_np\fR(3C),
403 \fBposix_spawnattr_setsigmask\fR(3C), \fBsched_setparam\fR(3C),
404 \fBsched_setscheduler\fR(3C), \fBsystem\fR(3C), \fBwait\fR(3C),
405 \fBattributes\fR(5), \fBstandards\fR(5)
406 .SH NOTES
409 The SUSv3 POSIX standard (The Open Group Base Specifications Issue 6, IEEE Std
410 1003.1-2001) permits the \fBposix_spawn()\fR and \fBposix_spawnp()\fR functions
411 to return successfully before some of the above-described errors are detected,
412 allowing the child process to fail instead:
414 .in +2
416 \&... if the error occurs after the calling process
417 successfully returns, the child process exits with
418 exit status 127.
420 .in -2
424 With the one exception of when the \fBPOSIX_SPAWN_NOEXECERR_NP\fR flag is
425 passed in the attributes structure, this behavior is not present in the Solaris
426 implementation. Any error that occurs before the new process image is
427 successfully constructed causes the \fBposix_spawn()\fR and
428 \fBposix_spawnp()\fR functions to return the corresponding non-zero error value
429 without creating a child process.
432 The \fBPOSIX_SPAWN_NOSIGCHLD_NP\fR, \fBPOSIX_SPAWN_WAITPID_NP\fR,
433 \fBPOSIX_SPAWN_NOEXECERR_NP\fR, and \fBPOSIX_SPAWN_SETSIGIGN_NP\fR flags and
434 the \fBposix_spawnattr_getsigignore_np()\fR and
435 \fBposix_spawnattr_setsigignore_np()\fR functions are non-portable Solaris
436 extensions to the \fBposix_spawn()\fR and \fBposix_spawnp()\fR interfaces.