1 .\" $NetBSD: fork1.9,v 1.13 2008/01/04 23:43:56 mjf Exp $
3 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
8 .\" NASA Ames Research Center.
10 .\" Redistribution and use in source and binary forms, with or without
11 .\" modification, are permitted provided that the following conditions
13 .\" 1. Redistributions of source code must retain the above copyright
14 .\" notice, this list of conditions and the following disclaimer.
15 .\" 2. Redistributions in binary form must reproduce the above copyright
16 .\" notice, this list of conditions and the following disclaimer in the
17 .\" documentation and/or other materials provided with the distribution.
19 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd create a new process
41 .Fn "fork1" "struct lwp *l1" "int flags" "int exitsig" "void *stack" "size_t stacksize" "void (*func)(void *)" "void *arg" "register_t *retval" "struct proc **rnewprocp"
44 creates a new process out of the process behind
46 which is assumed to be the current lwp.
47 This function is used primarily to implement the
51 system calls, but is versatile enough to be used as a backend for
58 argument controls the semantics of the fork operation, and is made up of
59 the bitwise-OR of the following values:
60 .Bl -tag -width FORK_SHAREFILES
62 The parent process will sleep until the child process successfully calls
64 or exits (either by a call to
68 The child process will share the parent's virtual address space.
69 If this flag is not specified, the child will get a copy-on-write
70 snapshot of the parent's address space.
72 The child process will share the parent's current directory, root directory,
73 and file creation mask.
75 The child process will share the parent's file descriptors.
77 The child process will share the parent's signal actions.
79 The child process will at creation time be inherited by the init process.
81 The child process will not copy or share the parent's descriptors, but
82 rather will start out with a clean set.
87 value of 0 indicates a standard fork operation.
91 argument controls the signal sent to the parent on child death.
92 If normal operation desired, SIGCHLD should be supplied.
94 It is possible to specify the child userspace stack location and size
99 arguments, respectively.
102 and 0, respectively, will give the child the default values
103 for the machine architecture in question.
109 can be used to specify a kernel function to be called when the child process
112 These are used for example in starting the init process and creating kernel
117 argument is provided for the use of system call stubs.
120 is not NULL, it will hold the following values after successful completion
121 of the fork operation:
122 .Bl -tag -width retval[0]
124 This will contain the pid of the child process.
126 In the parent process, this will contain the value 0.
127 In the child process, this will contain 1.
130 User level system call stubs typically subtract 1 from
132 and bitwise-AND it with
134 thus returning the pid to the parent process and 0 to the child.
140 will point to the newly created process upon successful completion of
143 Upon successful completion of the fork operation,
146 Otherwise, the following error values are returned:
147 .Bl -tag -width [EAGAIN]
149 The limit on the total number of system processes would be exceeded.
153 on the total number of processes under execution by this
154 user id would be exceeded.