FORK1(9) BSD Kernel Developer's Manual FORK1(9)
fork1 -- create a new process
fork1(struct proc *p1, int flags, void *stack, pid_t *tidptr,
void (*func)(void *), void *arg, register_t *retval,
struct proc **rnewprocp);
fork1() creates a new process out of p1, which should be the current
process. This function is used primarily to implement the fork(2),
__tfork(2), vfork(2) system calls, as well as the kthread_create(9) func-
The flags argument is used to control the behavior of the fork and is
created by a bitwise-OR of the following values:
FORK_FORK The call is done by the fork(2) system call. Used only
FORK_VFORK The call is done by the vfork(2) system call. Used only
FORK_TFORK The call is done by the __tfork(2) system call. Used
only for statistics.
FORK_PPWAIT Suspend the parent process until the child is terminated
(by calling _exit(2) or abnormally), or makes a call to
FORK_SHAREFILES Let the child share the file descriptor table with the
parent through fdshare(). The default behavior is to
copy the table through fdcopy().
FORK_IDLE The child will be left in the SIDL state. The default
behavior is to make it runnable and add it to the run
FORK_NOZOMBIE The child will be dissociated from the parent and will
not leave a status for the parent to collect. See
FORK_SHAREVM The child will share the parent's address space. The
default behavior is that the child gets a copy-on-write
copy of the address space.
FORK_SIGHAND The child will share the parent's signal actions,
including the handler, mask, and flags, with
sigactsshare(). The default behavior is to copy the
signal actions from the parent with sigactsinit().
FORK_SHAREVM must also be set.
FORK_PTRACE The child will start with tracing enabled, as if
ptrace(PT_TRACE_ME, 0, 0, 0) had been invoked in the
FORK_THREAD The child will instead be a kernel-level thread in the
same process as the parent. FORK_SHAREFILES,
FORK_SHAREVM, and FORK_SIGHAND must also be set.
If stack is not NULL, it will be used as the initial value of the child's
stack pointer, instead of using the child's copy of the parent's stack.
If tidptr is not NULL, the PID of the child process will be written there
in the parent on success. This is guaranteed to be done before the child
process is started.
If retval is not NULL, it will hold the following values after successful
completion of the fork operation:
retval This will contain the PID of the child process.
retval In the parent process, this will contain the value 0. In the
child process, this will contain 1.
If func is not NULL, the new process will begin execution by calling this
function. It defaults to child_return, which returns to userland.
If arg is not NULL, it is the argument to the previous function. It
defaults to a pointer to the new process.
The newly created process is returned through *rnewprocp.
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
[EAGAIN] The limit RLIMIT_NPROC on the total number of processes under
execution by this user id would be exceeded.
__tfork(2), execve(2), fork(2), vfork(2), kthread_create(9), pfind(9),
The fork1 function semantics are specific to OpenBSD. Other BSD systems
have different semantics.
BSD July 7, 2014 BSD