1.\" $NetBSD: fork1.9,v 1.5 2002/02/13 08:18:41 ross Exp $ 2.\" 3.\" Copyright (c) 1998 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 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. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 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. 18.\" 3. All advertising materials mentioning features or use of this software 19.\" must display the following acknowledgement: 20.\" This product includes software developed by the NetBSD 21.\" Foundation, Inc. and its contributors. 22.\" 4. Neither the name of The NetBSD Foundation nor the names of its 23.\" contributors may be used to endorse or promote products derived 24.\" from this software without specific prior written permission. 25.\" 26.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36.\" POSSIBILITY OF SUCH DAMAGE. 37.\" 38.Dd January 6, 1998 39.Dt FORK1 9 40.Os 41.Sh NAME 42.Nm fork1 43.Nd create a new process 44.Sh SYNOPSIS 45.Fd #include \*[Lt]sys/types.h\*[Gt] 46.Fd #include \*[Lt]sys/proc.h\*[Gt] 47.Ft int 48.Fn "fork1" "struct proc *p1" "int flags" "register_t *retval" "struct proc **rnewprocp" 49.Sh DESCRIPTION 50.Fn fork1 51creates a new process out of 52.Ar p1 , 53which is assumed to be the current process. This function is used primarily 54to implement the 55.Xr fork 2 56and 57.Xr vfork 2 58system calls. 59.Pp 60The 61.Ar flags 62argument controls the semantics of the fork operation, and is made up of 63the bitwise-OR of the following values: 64.Bl -tag -width FORK_SHAREVM 65.It FORK_PPWAIT 66The parent process will sleep until the child process successfully calls 67.Xr execve 2 68or exits (either by a call to 69.Xr _exit 2 70or abnormally). 71.It FORK_SHAREVM 72The child process will share the parent's virtual address space. If this 73flag is not specified, the child will get a copy-on-write snapshot of the 74parent's address space. 75.El 76.Pp 77A 78.Ar flags 79value of 0 indicates a standard fork operation. 80.Pp 81The 82.Ar retval 83argument is provided for the use of system call stubs. If 84.Ar retval 85is not NULL, it will hold the following values after successful completion 86of the fork operation: 87.Bl -tag -width retval[0] 88.It Ar retval[0] 89This will contain the pid of the child process. 90.It Ar retval[1] 91In the parent process, this will contain the value 0. In the child process, 92this will contain 1. 93.El 94.Pp 95User level system call stubs typically subtract 1 from 96.Ar retval[1] 97and bitwise-AND it with 98.Ar retval[0] , 99thus returning the pid to the parent process and 0 to the child. 100.Pp 101If 102.Ar rnewprocp 103is not NULL, 104.Ar *rnewprocp 105will point to the newly created process upon successful completion of 106the fork operation. 107.Sh RETURN VALUES 108Upon successful completion of the fork operation, 109.Fn fork1 110returns 0. Otherwise, the following error values are returned: 111.Bl -tag -width [EAGAIN] 112.It Bq Er EAGAIN 113The limit on the total number of system processes would be exceeded. 114.It Bq Er EAGAIN 115The limit 116.Dv RLIMIT_NPROC 117on the total number of processes under execution by this 118user id would be exceeded. 119.El 120.Sh SEE ALSO 121.Xr execve 2 , 122.Xr fork 2 , 123.Xr vfork 2 124