2 .\" Copyright (c) 2000-2010 Apple Inc. All rights reserved.
4 .\" @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 .\" This file contains Original Code and/or Modifications of Original Code
7 .\" as defined in and that are subject to the Apple Public Source License
8 .\" Version 2.0 (the 'License'). You may not use this file except in
9 .\" compliance with the License. The rights granted to you under the License
10 .\" may not be used to create, or enable the creation or redistribution of,
11 .\" unlawful or unlicensed copies of an Apple operating system, or to
12 .\" circumvent, violate, or enable the circumvention or violation of, any
13 .\" terms of an Apple operating system software license agreement.
15 .\" Please obtain a copy of the License at
16 .\" http://www.opensource.apple.com/apsl/ and read it before using this file.
18 .\" The Original Code and all software distributed under the License are
19 .\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 .\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 .\" Please see the License for the specific language governing rights and
24 .\" limitations under the License.
26 .\" @APPLE_OSREFERENCE_LICENSE_HEADER_END@
38 .Fd #include <spawn.h>
41 .Fa "pid_t *restrict pid"
42 .Fa "const char *restrict path"
43 .Fa "const posix_spawn_file_actions_t *file_actions"
44 .Fa "const posix_spawnattr_t *restrict attrp"
45 .Fa "char *const argv[restrict]"
46 .Fa "char *const envp[restrict]"
50 .Fa "pid_t *restrict pid"
51 .Fa "const char *restrict file"
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]"
60 function creates a new process from the executable file, called the
61 .Em new process file ,
64 which is an absolute or relative path to the file.
67 function is identical to the
71 specified contains a slash character; otherwise, the
73 parameter is used to construct a pathname, with its path prefix being
74 obtained by a search of the path specified in the environment by the
75 .Dq Ev PATH variable .
76 If this variable isn't specified, the default path is set according
82 .Dq Ev /usr/bin:/bin .
83 This pathname either refers to an executable object file,
84 or a file of data for an interpreter;
90 is a pointer to a pid_t variable to receive the pid of the spawned
91 process; if this is NULL, then the pid of the spawned process is
92 not returned. If this pointer is non-NULL, then on successful
93 completion, the variable will be modified to contain the pid of the
94 spawned process. The value is undefined in the case of a failure.
98 is either NULL, or it is a pointer to a file actions object that was
99 initialized by a call to
100 .Xr posix_spawn_file_actions_init 3
101 and represents zero or more file actions.
103 File descriptors open in the calling process image remain open in
104 the new process image, except for those for which the close-on-exec
109 Descriptors that remain open are unaffected by
111 unless their behaviour is modified by particular spawn flags
112 or a file action; see
113 .Xr posix_spawnattr_setflags 3
115 .Xr posix_spawn_file_actions_init 3
116 for additional information.
120 is either NULL, or it is a pointer to an attributes object that was
121 initialized by a call to
122 .Xr posix_spawnattr_init 3
123 and represents a set of spawn attributes to apply. If NULL, then the
124 default attributes are applied; otherwise, these attributes can control
125 various aspects of the spawned process, and are applied prior to the
126 spawned process beginning execution; see
127 .Xr posix_spawnattr_init 3
128 for more information.
132 is a pointer to a null-terminated array of
133 character pointers to null-terminated character strings.
134 These strings construct the argument list to be made available to the new
137 must be present in the array, and should contain the file name of the
138 program being spawned, e.g. the last component of the
146 is a pointer to a null-terminated array of character pointers to
147 null-terminated strings. A pointer to this array is normally stored
148 in the global variable
150 These strings pass information to the
151 new process that is not directly an argument to the command (see
154 Signals set to be ignored in the calling process are set to be ignored in
155 the new process, unless the behaviour is modified by user specified
156 .Em spawn attributes .
157 Signals which are set to be caught in the calling process image are set to
158 default action in the new process image.
159 Blocked signals remain blocked regardless of changes to the signal action,
160 unless the mask is overridden by user specified
161 .Em spawn attributes .
162 The signal stack is reset to be undefined (see
164 for more information).
166 By default, the effective user ID and group ID will be the same as those of
167 the calling process image; however, this may be overridden to force them to
168 be the real user ID and group ID of the parent process by user specified
171 .Xr posix_spawnattr_init 3
172 for more information).
174 If the set-user-ID mode bit of the new process image file is set
177 the effective user ID of the new process image is set to the owner ID
178 of the new process image file.
179 If the set-group-ID mode bit of the new process image file is set,
180 the effective group ID of the new process image is set to the group ID
181 of the new process image file.
182 (The effective group ID is the first element of the group list.)
183 The real user ID, real group ID and supplementary group IDs of the new
184 process image remain the same as the calling process image.
185 After any set-user-ID and set-group-ID processing,
186 the effective user ID is recorded as the saved set-user-ID,
187 and the effective group ID is recorded as the saved set-group-ID.
188 These values may be used in changing the effective IDs later (see
191 The new process also inherits the following attributes from
194 .Bl -column parent_process_ID -offset indent -compact
195 .It parent process ID Ta see Xr getppid 2
196 .It process group ID Ta see Xr getpgrp 2 , Xr posix_spawnattr_init 3
197 .It access groups Ta see Xr getgroups 2
198 .It working directory Ta see Xr chdir 2
199 .It root directory Ta see Xr chroot 2
200 .It control terminal Ta see Xr termios 4
201 .It resource usages Ta see Xr getrusage 2
202 .It interval timers Ta see Xr getitimer 2
203 .It resource limits Ta see Xr getrlimit 2
204 .It file mode mask Ta see Xr umask 2
205 .It signal mask Ta see Xr sigaction 2 , Xr sigsetmask 2 ,
206 .Xr posix_spawnattr_init 3
209 When a program is executed as a result of a
213 call, it is entered as follows:
214 .Bd -literal -offset indent
215 main(argc, argv, envp)
222 is the number of elements in
227 points to the array of character pointers
228 to the arguments themselves.
232 argument is NULL, no pid is returned to the calling process; if it is
237 functions return the process ID of the child process into the pid_t
238 variable pointed to by the
240 argument and return a 0 on success. If an error occurs, they return
241 a non-zero error code as the function return value, and no child process
248 functions will fail and return to the calling process if:
252 The value specified by
259 The number of bytes in the new process's argument list
260 is larger than the system-imposed limit.
261 This limit is specified by the
267 Search permission is denied for a component of the path prefix.
270 The new process file is not an ordinary file.
273 The new process file mode denies execute permission.
276 The new process file is on a filesystem mounted
277 with execution disabled
280 .Ao Pa sys/mount.h Ac ) .
283 The new process file is not as long as indicated by
284 the size values in its header.
292 to an illegal address.
295 An I/O error occurred while reading from the file system.
298 Too many symbolic links were encountered in translating the pathname.
299 This is taken to be indicative of a looping symbolic link.
301 .It Bq Er ENAMETOOLONG
302 A component of a pathname exceeded
304 characters, or an entire path name exceeded
309 The new process file does not exist.
312 The new process file has the appropriate access
313 permission, but has an unrecognized format
314 (e.g., an invalid magic number in its header).
317 The new process requires more virtual memory than
318 is allowed by the imposed maximum
322 A component of the path prefix is not a directory.
325 The new process file is a pure procedure (shared text)
326 file that is currently open for writing or reading by some process.
331 to a non-super-user, but is executed when
334 is ``root'', then the program has some of the powers
335 of a super-user as well.
342 .Xr posix_spawnattr_init 3 ,
343 .Xr posix_spawn_file_actions_init 3 ,
351 function calls appeared in