| FORK1(9) | Kernel Developer's Manual | FORK1(9) |
fork1 — create a
new process
#include
<sys/types.h>
#include <sys/proc.h>
int
fork1(struct proc *p1,
int flags, void (*func)(void *),
void *arg, register_t *retval,
struct proc **rnewprocp);
fork1()
creates a new process out of p1, which should be the
current thread. This function is used primarily to implement the
fork(2) and vfork(2) system calls, as
well as the kthread_create(9) function.
The flags argument is used to control the behavior of the fork and is created by a bitwise-OR of the following values:
FORK_FORKFORK_VFORKFORK_PPWAITFORK_SHAREFILESfdshare().
The default behavior is to copy the table through
fdcopy().FORK_IDLESIDL state. The
default behavior is to make it runnable and add it to the run queue.FORK_NOZOMBIEFORK_SHAREVMFORK_SYSTEMFORK_PTRACEThe new thread will begin execution by calling
func, which must not be NULL.
If arg is not NULL, it is
passed as the argument to func. Otherwise, a pointer
to the new process's only thread is passed.
If retval is not
NULL, the PID of the child process will be stored in
*retval on successful completion.
If rnewprocp is not
NULL, the newly created thread is stored in
*rnewprocp on successful completion.
Upon successful completion of the fork operation,
fork1() returns 0. Otherwise, the following error
values are returned:
EAGAIN]EAGAIN]RLIMIT_NPROC on the total number of
processes under execution by this user id would be exceeded.ENOMEM]execve(2), fork(2), vfork(2), kthread_create(9), psignal(9), tfind(9)
The fork1 function semantics are specific
to OpenBSD. Other BSD
systems have different semantics.
| December 29, 2022 | Debian |