.\" $NetBSD: fork1.9,v 1.1 1998/01/07 00:30:02 thorpej Exp $ .\" .\" Copyright (c) 1998 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, .\" NASA Ames Research Center. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the NetBSD .\" Foundation, Inc. and its contributors. .\" 4. Neither the name of The NetBSD Foundation nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd January 6, 1998 .Dt FORK1 9 .Os NetBSD .Sh NAME .Nm fork1 .Nd create a new process .Sh SYNOPSIS .Ft int .Fn "fork1" "struct proc *p1" "int flags" "register_t *retval" "struct proc **rnewprocp" .Sh DESCRIPTION .Fn fork1 creates a new process out of .Ar p1 , which is assumed to be the current process. This function is used primarily to implement the .Xr fork 2 and .Xr vfork 2 system calls. .Pp The .Ar flags argument controls the semantics of the fork operation, and is made up of the bitwise-OR of the following values: .Bl -tag -width FORK_SHAREVM .It FORK_PPWAIT The parent process will sleep until the child process successfully calls .Xr execve 2 or exits (either by a call to .Xr _exit 2 or abormally). .It FORK_SHAREVM The child process will share the parent's virtual address space. If this flag is not specified, the child will get a copy-on-write snapshot of the parent's address space. .El .Pp A .Ar flags value of 0 indicates a standard fork operation. .Pp The .Ar retval argument is provided for the use of system call stubs. If .Ar retval is not NULL, it will hold the following values after successful completion of the fork operation: .Bl -tag -width retval[0] .It Ar retval[0] This will contain the pid of the child process. .It Ar retval[1] In the parent process, this will contain the value 0. In the child process, this will contain 1. .El .Pp User level system call stubs typically subtract 1 from .Ar retval[1] and bitwise-AND it with .Ar retval[0] , thus returning the pid to the parent process and 0 to the child. .Pp If .Ar rnewprocp is not NULL, .Ar *rnewprocp will point to the newly created process upon successful completion of the fork operation. .Sh RETURN VALUES Upon successful completion of the fork operation, .Fn fork1 returns 0. Otherwise, the following error values are returned: .Bl -tag -width [EAGAIN] .It Bq Er EAGAIN The limit on the total number of system processes would be exceeded. .It Bq Er EAGAIN The limit .Dv RLIMIT_NPROC on the total number of processes under execution by this user id would be exceeded. .El .Sh SEE ALSO .Xr execve 2 , .Xr fork 2 , .Xr vfork 2