2002-08-06 18:00:03 +04:00
|
|
|
.\" $NetBSD: fork1.9,v 1.7 2002/08/06 14:00:03 pooka Exp $
|
1998-01-07 03:30:02 +03:00
|
|
|
.\"
|
|
|
|
.\" 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
|
1999-03-16 03:40:46 +03:00
|
|
|
.Os
|
1998-01-07 03:30:02 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm fork1
|
|
|
|
.Nd create a new process
|
|
|
|
.Sh SYNOPSIS
|
2002-02-13 11:17:26 +03:00
|
|
|
.Fd #include \*[Lt]sys/types.h\*[Gt]
|
|
|
|
.Fd #include \*[Lt]sys/proc.h\*[Gt]
|
1998-01-07 03:30:02 +03:00
|
|
|
.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:
|
2002-07-11 14:45:58 +04:00
|
|
|
.Bl -tag -width FORK_SHAREFILES
|
1998-01-07 03:30:02 +03:00
|
|
|
.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
|
2001-06-21 15:59:00 +04:00
|
|
|
or abnormally).
|
1998-01-07 03:30:02 +03:00
|
|
|
.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.
|
2002-07-11 14:45:58 +04:00
|
|
|
.It FORK_SHARECWD
|
|
|
|
The child process will share the parent's current directory, root directory,
|
|
|
|
and file creation mask.
|
|
|
|
.It FORK_SHAREFILES
|
|
|
|
The child process will share the parent's file descriptors.
|
|
|
|
.It FORK_SHARESIGS
|
|
|
|
The child process will share the parent's signal actions.
|
|
|
|
.It FORK_NOWAIT
|
|
|
|
The child process will at creation time be inherited by the init process.
|
2002-08-06 18:00:03 +04:00
|
|
|
.It FORK_CLEANFILES
|
|
|
|
The child process will not copy or share the parent's descriptors, but
|
|
|
|
rather will start out with a clean set.
|
1998-01-07 03:30:02 +03:00
|
|
|
.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
|