1.\" Copyright (c) 1980, 1991 Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)fork.2 6.5 (Berkeley) 03/10/91 7.\" 8.Dd 9.Dt FORK 2 10.Os BSD 4.0 11.Sh NAME 12.Nm fork 13.Nd create a new process 14.Sh SYNOPSIS 15.Fd #include <unistd.h> 16.Ft pid_t 17.Fn fork void 18.Sh DESCRIPTION 19.Fn Fork 20causes creation of a new process. 21The new process (child process) is an exact copy of the 22calling process (parent process) except for the following: 23.Bl -bullet -offset indent 24.It 25The child process has a unique process ID. 26.It 27The child process has a different parent 28process ID (i.e., the process ID of the parent process). 29.It 30The child process has its own copy of the parent's descriptors. 31These descriptors reference the same underlying objects, so that, 32for instance, file pointers in file objects are shared between 33the child and the parent, so that an 34.Xr lseek 2 35on a descriptor in the child process can affect a subsequent 36.Xr read 37or 38.Xr write 39by the parent. 40This descriptor copying is also used by the shell to 41establish standard input and output for newly created processes 42as well as to set up pipes. 43.It 44The child processes resource utilizations 45are set to 0; see 46.Xr setrlimit 2 . 47.El 48.Sh RETURN VALUES 49Upon successful completion, 50.Fn fork 51returns a value 52of 0 to the child process and returns the process ID of the child 53process to the parent process. Otherwise, a value of -1 is returned 54to the parent process, no child process is created, and the global 55variable 56.Va errno 57is set to indicate the error. 58.Sh ERRORS 59.Fn Fork 60will fail and no child process will be created if: 61.Bl -tag -width [EAGAIN] 62.It Bq Er EAGAIN 63The system-imposed limit on the total 64number of processes under execution would be exceeded. 65This limit is configuration-dependent. 66.It Bq Er EAGAIN 67The system-imposed limit 68.Dv MAXUPRC 69.Pq Aq Pa sys/param.h 70on the total number of 71processes under execution by a single user would be exceeded. 72.It Bq Er ENOMEM 73There is insufficient swap space for the new process. 74.El 75.Sh SEE ALSO 76.Xr execve 2 , 77.Xr wait 2 78.Sh HISTORY 79A 80.Nm 81function call appeared in Version 6 AT&T UNIX. 82