Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

fork1(9) [netbsd man page]

FORK1(9)						   BSD Kernel Developer's Manual						  FORK1(9)

NAME
fork1 -- create a new process SYNOPSIS
#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, struct proc **rnewprocp); DESCRIPTION
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: FORK_PPWAIT The parent process will sleep until the child process successfully calls execve(2) or exits (either by a call to _exit(2) or abnormally). FORK_SHAREVM The child process will share the parent's virtual address space. If this flag is not specified, the child will get a copy- on-write snapshot of the parent's address space. FORK_SHARECWD The child process will share the parent's current directory, root directory, and file creation mask. FORK_SHAREFILES The child process will share the parent's file descriptors. FORK_SHARESIGS The child process will share the parent's signal actions. FORK_NOWAIT The child process will at creation time be inherited by the init process. FORK_CLEANFILES The child process will not copy or share the parent's descriptors, but rather will start out with a clean set. 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: 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. 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. If rnewprocp is not NULL, *rnewprocp will point to the newly created process upon successful completion of the fork operation. 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 exceeded. [EAGAIN] The limit RLIMIT_NPROC on the total number of processes under execution by this user id would be exceeded. SEE ALSO
execve(2), fork(2), vfork(2) BSD
January 4, 2008 BSD

Check Out this Related Man Page

FORK(2) 						      BSD System Calls Manual							   FORK(2)

NAME
fork -- create a new process SYNOPSIS
#include <sys/types.h> #include <unistd.h> pid_t fork(void); DESCRIPTION
Fork() causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent process) except for the following: o The child process has a unique process ID. o The child process has a different parent process ID (i.e., the process ID of the parent process). o The child process has its own copy of the parent's descriptors. These descriptors reference the same underlying objects, so that, for instance, file pointers in file objects are shared between the child and the parent, so that an lseek(2) on a descriptor in the child process can affect a subsequent read or write by the parent. This descriptor copying is also used by the shell to establish standard input and output for newly created processes as well as to set up pipes. o The child processes resource utilizations are set to 0; see setrlimit(2). RETURN VALUES
Upon successful completion, fork() returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable errno is set to indicate the error. ERRORS
Fork() will fail and no child process will be created if: [EAGAIN] The system-imposed limit on the total number of processes under execution would be exceeded. This limit is configuration- dependent. [EAGAIN] The system-imposed limit MAXUPRC (<sys/param.h>) on the total number of processes under execution by a single user would be exceeded. [ENOMEM] There is insufficient swap space for the new process. SEE ALSO
execve(2), wait(2) HISTORY
A fork() function call appeared in Version 6 AT&T UNIX. 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution
Man Page