xref: /openbsd-src/share/man/man9/fork1.9 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: fork1.9,v 1.6 2001/08/03 15:21:17 mpech Exp $
2.\"	$NetBSD: fork1.9,v 1.3 1999/03/16 00:40:47 garbled Exp $
3.\"
4.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
5.\" All rights reserved.
6.\"
7.\" This code is derived from software contributed to The NetBSD Foundation
8.\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9.\" NASA Ames Research Center.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. All advertising materials mentioning features or use of this software
20.\"    must display the following acknowledgement:
21.\"        This product includes software developed by the NetBSD
22.\"        Foundation, Inc. and its contributors.
23.\" 4. Neither the name of The NetBSD Foundation nor the names of its
24.\"    contributors may be used to endorse or promote products derived
25.\"    from this software without specific prior written permission.
26.\"
27.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37.\" POSSIBILITY OF SUCH DAMAGE.
38.\"
39.Dd January 6, 1998
40.Dt FORK1 9
41.Os
42.Sh NAME
43.Nm fork1
44.Nd create a new process
45.Sh SYNOPSIS
46.Fd #include <sys/types.h>
47.Fd #include <sys/proc.h>
48.Ft int
49.Fn "fork1" "struct proc *p1" "int flags" "void *stack" "size_t stacksize" "register_t *retval"
50.Sh DESCRIPTION
51.Fn fork1
52creates a new process out of
53.Ar p1 ,
54which should be the current process.
55This function is used primarily to implement the
56.Xr fork 2 ,
57.Xr rfork 2 ,
58.Xr vfork 2
59system calls, as well as the
60.Xr kthread_create 9
61function.
62.Pp
63The
64.Ar flags
65argument is used to control the behavior of the fork and is created by
66a bitwise-OR of the following values:
67.Bl -tag -width FORK_SHAREFILES
68.It Dv FORK_FORK
69The call is done by the
70.Xr fork 2
71system call.
72Used only for statistics.
73.It Dv FORK_VFORK
74The call is done by the
75.Xr vfork 2
76system call.
77Used only for statistics.
78.It Dv FORK_RFORK
79The call is done by the
80.Xr rfork 2
81system call.
82Used only for statistics.
83.It Dv FORK_PPWAIT
84Suspend the parent process until the child is terminated (by calling
85.Xr _exit 2
86or abnormally), or makes a call to
87.Xr execve 2 .
88.It Dv FORK_SHAREFILES
89Let the child share the file descriptor table with the parent through
90.Xr fdshare 9 .
91The default behavior is to copy the table through
92.Xr fdcopy 9 .
93.It Dv FORK_CLEANFILES
94The child starts with a clean file descriptor table created by
95.Xr fdinit 9 .
96.It Dv FORK_NOZOMBIE
97The child will be dissociated from the parent and will not leave a status
98for the parent to collect.
99See
100.Xr wait 2 .
101.It Dv FORK_SHAREVM
102The child will share the parent's address space.
103The default behavior is
104that the child gets a copy-on-write copy of the address space.
105.El
106.Pp
107If
108.Fa stack
109is not
110.Dv NULL ,
111the area starting at
112.Fa stack
113of extent
114.Fa stacksize
115will be used for the child's stack, instead of cloning the parent's
116stack.
117.Pp
118If
119.Fa retval
120is not
121.Dv NULL ,
122it will hold the following values after successful completion
123of the fork operation:
124.Bl -tag -width retval[0]
125.It Fa retval[0]
126This will contain the pid of the child process.
127.It Fa retval[1]
128In the parent process, this will contain the value 0.
129In the child process, this will contain 1.
130.El
131.Sh RETURN VALUES
132Upon successful completion of the fork operation,
133.Fn fork1
134returns 0.
135Otherwise, the following error values are returned:
136.Bl -tag -width [EAGAIN]
137.It Bq Er EAGAIN
138The limit on the total number of system processes would be exceeded.
139.It Bq Er EAGAIN
140The limit
141.Dv RLIMIT_NPROC
142on the total number of processes under execution by this
143user id would be exceeded.
144.El
145.Sh CAVEATS
146The
147.Nm
148function semantics are specific to
149.Ox .
150Other BSD systems have different semantics.
151.Pp
152The system never uses
153.Fn fork1
154with a non-null
155.Fa stack ,
156so that feature is not even tested.
157.Sh SEE ALSO
158.Xr execve 2 ,
159.Xr fork 2 ,
160.Xr rfork 2 ,
161.Xr vfork 2 ,
162.Xr kthread_create 9 ,
163.Xr pfind 9 ,
164.Xr psignal 9
165