| FORK1(9) | Kernel Developer's Manual | FORK1(9) | 
fork1 —
#include <sys/types.h>
#include <sys/proc.h>
int
  
  fork1(struct
    lwp *l1, int flags,
    int exitsig,
    void *stack,
    size_t stacksize,
    void (*func)(void *),
    void *arg,
    register_t *retval);
fork1() creates a new process out of the process behind
  l1, which is assumed to be the current lwp. This
  function is used primarily to implement the
  fork(2) and
  vfork(2) system calls, but is
  versatile enough to be used as a backend for e.g. the
  __clone(2) call.
The flags argument controls the semantics of the fork operation, and is made up of the bitwise-OR of the following values:
A flags value of 0 indicates a standard fork operation.
The exitsig argument controls the signal sent to the parent on child death. If normal operation desired, SIGCHLD should be supplied.
It is possible to specify the child userspace stack location and
    size by using the stack and
    stacksize arguments, respectively. Values
    NULL and 0, respectively, will give the child the
    default values for the machine architecture in question.
The arguments func and
    arg can be used to specify a kernel function to be
    called when the child process returns instead of
    child_return(). These are used for example in
    starting the init process and creating kernel threads.
The retval argument is provided for the use of system call stubs. If retval is not NULL, it will hold the following values after successful completion of the fork operation:
User level system call stubs typically subtract 1 from retval[1] and bitwise-AND it with retval[0], thus returning the pid to the parent process and 0 to the child.
fork1() returns 0. Otherwise, the following error
  values are returned:
EAGAIN]RLIMIT_NPROC on the total number of
      processes under execution by this user id would be exceeded.| April 16, 2018 | NetBSD 10.0 |