.\" $OpenBSD: rfork.2,v 1.19 2003/06/18 11:05:21 jmc Exp $ .\" .\" Copyright (c) 2003 Jason McIntyre .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd June 17, 2003 .Dt RFORK 2 .Os .Sh NAME .Nm rfork .Nd control new processes .Sh SYNOPSIS .Fd #include .Fd #include .Ft int .Fn rfork "int flags" .Sh DESCRIPTION The fork functions .Pf ( Xr fork 2 , .Xr vfork 2 and .Fn rfork ) create new processes. The new process (child process) is an exact copy of the calling process (parent process), except as outlined in the .Xr fork 2 manual page. .Fn rfork can be used to manipulate the resources of the parent process and the child process. Operations currently supported include whether to copy or share the file descriptor table between the two processes, whether to share the address space, and whether the parent should .Xr wait 2 for the child process to .Xr _exit 2 . .Fn rfork takes a single argument, .Fa flags , which controls which of these resources should be manipulated. They are defined in the header file .Aq Pa sys/param.h and are the logical OR of one or more of the following: .Pp .Bl -tag -width "RFNOWAIT" .It Dv RFNAMEG New Plan 9 .Sq name space . This is a Plan 9 specific flag, and not implemented. .It Dv RFENVG Copy Plan 9 .Sq env space . This is a Plan 9 specific flag, and not implemented. .It Dv RFFDG Copy the parent's file descriptor table. If this flag is unset, the parent and child will share the parent's file descriptor table. May not be used in conjunction with .Dv RFCFDG . .It Dv RFNOTEG Create new Plan 9 .Sq note group . This is a Plan 9 specific flag, and not implemented. .It Dv RFPROC Create a new process. The current implementation requires this flag to always be set. .It Dv RFMEM The kernel forces sharing of the entire address space. The child will then inherit all the shared segments the parent process owns. Subsequent forks by the parent will then propagate the shared data and bss between children. The stack segment is always split. .It Dv RFNOWAIT Parent need not .Xr wait 2 on child. .It Dv RFCNAMEG Zero Plan 9 .Sq name space . This is a Plan 9 specific flag, and not implemented. .It Dv RFCENVG Zero Plan 9 .Sq env space . This is a Plan 9 specific flag, and not implemented. .It Dv RFCFDG Zero the child's file descriptor table (ie. start with a blank file descriptor table). May not be used in conjunction with .Dv RFFDG . .El .Sh RETURN VALUES The parent process returns the process ID (PID) of the child process. The child process returns 0. The range of the process ID is defined in .Aq Pa sys/proc.h and is currently between 1 and 32766, inclusive. .Pp .Fn fork can be implemented as a call to .Fn rfork using "RFFDG|RFPROC", but isn't for backwards compatibility. If a process has file descriptor table sharing active, setuid or setgid programs will not .Xr execve 2 with extra privileges. .Sh ERRORS .Fn rfork will fail and no child process will be created if: .Bl -tag -width Er .It Bq Er ENOMEM Cannot allocate memory. The new process image required more memory than was allowed by the hardware or by system-imposed memory management constraints. A lack of swap space is normally temporary; however, a lack of core is not. Soft limits may be increased to their corresponding hard limits. .It Bq Er EINVAL Invalid argument. Some invalid argument was supplied. .It Bq Er EAGAIN Resource temporarily unavailable. The system-imposed limit on the total number of processes under execution would be exceeded. This limit is configuration-dependent. .It Bq Er EAGAIN Resource temporarily unavailable. The system-imposed limit .Dv MAXUPRC on the total number of processes under execution by a single user would be exceeded. .Dv MAXUPRC is currently defined in .Aq Pa sys/param.h as .Dv CHILD_MAX , which is currently defined as 80 in .Aq Pa sys/limits.h . .El .Sh SEE ALSO .Xr _exit 2 , .Xr execve 2 , .Xr fork 2 , .Xr intro 2 , .Xr vfork 2 .Sh HISTORY The .Fn rfork function first appeared in Plan 9.