FORK1(9)                     OpenBSD Kernel Manual                    FORK1(9)

NAME
     fork1 - create a new process

SYNOPSIS
     #include <sys/types.h>
     #include <sys/proc.h>

     int
     fork1(struct proc *p1, int forktype, int rforkflags, void *stack,
             size_t stacksize, register_t *retval);

DESCRIPTION
     fork1() creates a new process out of p1, which should be the current pro-
     cess.  This function is used primarily to implement the fork(2),
     rfork(2),  vfork(2) system calls, as well as the create_kthread(9) func-
     tion.

     The forktype argument can be ISFORK, ISVFORK or ISRFORK and controls
     whether fork1 has fork(2),  vfork(2) or rfork(2) semantics.

     The rforkflags argument is only used if forktype equals ISRFORK, and is
     used to implement rfork(2) semantics.

     RFPROC    Should always be set. The system currently does not support
               changing an existing process characteristics.

     RFNOWAIT  See rfork(2).

     RFFDG     If set, the child gets a copy of the parent's file descriptor
               table through fdcopy(9).  Otherwise, the file descriptor table
               is shared through fdshare(9).

     RFCFDG    If set, the child starts out with a clean file descriptor table
               created by fdinit(9).

     RFMEM     If set, the child will share the parent's address space, apart
               from the stack segment, which is always copied.  Otherwise, the
               child will get a copy-on-write snapshot of the parent address
               space.

     If stack is not NULL, the area starting at stack of extent stacksize will
     be used for the child's stack, instead of cloning the parent's stack.

     If retval is not NULL, it will hold the following values after successful
     completion of the fork operation:

     retval[0]  This will contain the pid of the child process.

     retval[1]  In the parent process, this will contain the value 0.  In the
                child process, this will contain 1.

RETURN VALUES
     Upon successful completion of the fork operation, fork1() returns 0.
     Otherwise, the following error values are returned:

     [EAGAIN]  The limit on the total number of system processes would be ex-
               ceeded.

     [EAGAIN]  The limit RLIMIT_NPROC on the total number of processes under
               execution by this user id would be exceeded.

CAVEATS
     The fork1 function semantics are specific to OpenBSD. Other BSD systems
     have different semantics.

     The system never uses fork1() with a non-null stack, so that feature is
     not even tested.

SEE ALSO
     execve(2),  fork(2),  rfork(2),  vfork(2),  pfind(9),  psignal(9),  cre-
     ate_kthread(9)

OpenBSD 2.6                     January 6, 1998                              2
