[9] | 1 | .\" Copyright (c) 1980 Regents of the University of California.
|
---|
| 2 | .\" All rights reserved. The Berkeley software License Agreement
|
---|
| 3 | .\" specifies the terms and conditions for redistribution.
|
---|
| 4 | .\"
|
---|
| 5 | .\" @(#)fork.2 6.4 (Berkeley) 5/22/86
|
---|
| 6 | .\"
|
---|
| 7 | .TH FORK 2 "May 22, 1986"
|
---|
| 8 | .UC
|
---|
| 9 | .SH NAME
|
---|
| 10 | fork \- create a new process
|
---|
| 11 | .SH SYNOPSIS
|
---|
| 12 | .nf
|
---|
| 13 | .ft B
|
---|
| 14 | #include <sys/types.h>
|
---|
| 15 | #include <unistd.h>
|
---|
| 16 |
|
---|
| 17 | pid_t fork(void)
|
---|
| 18 | .ft R
|
---|
| 19 | .fi
|
---|
| 20 | .SH DESCRIPTION
|
---|
| 21 | .de SP
|
---|
| 22 | .if t .sp 0.4
|
---|
| 23 | .if n .sp
|
---|
| 24 | ..
|
---|
| 25 | .B Fork
|
---|
| 26 | causes creation of a new process.
|
---|
| 27 | The new process (child process) is an exact copy of the
|
---|
| 28 | calling process except for the following:
|
---|
| 29 | .RS
|
---|
| 30 | .SP
|
---|
| 31 | The child process has a unique process ID.
|
---|
| 32 | .SP
|
---|
| 33 | The child process has a different parent process ID (i.e.,
|
---|
| 34 | the process ID of the parent process).
|
---|
| 35 | .SP
|
---|
| 36 | The child process has its own copy of the parent's descriptors.
|
---|
| 37 | These descriptors reference the same underlying objects, so that,
|
---|
| 38 | for instance, file pointers in file objects are shared between
|
---|
| 39 | the child and the parent, so that an
|
---|
| 40 | .BR lseek (2)
|
---|
| 41 | on a descriptor in the child process can affect a subsequent
|
---|
| 42 | .B read
|
---|
| 43 | or
|
---|
| 44 | .B write
|
---|
| 45 | by the parent.
|
---|
| 46 | This descriptor copying is also used by the shell to
|
---|
| 47 | establish standard input and output for newly created processes
|
---|
| 48 | as well as to set up pipes.
|
---|
| 49 | .SP
|
---|
| 50 | The child starts with no pending signals and an inactive alarm timer.
|
---|
| 51 | .RE
|
---|
| 52 | .SH "RETURN VALUE
|
---|
| 53 | Upon successful completion, \fBfork\fP returns a value
|
---|
| 54 | of 0 to the child process and returns the process ID of the child
|
---|
| 55 | process to the parent process. Otherwise, a value of \-1 is returned
|
---|
| 56 | to the parent process, no child process is created, and the global
|
---|
| 57 | variable \fBerrno\fP is set to indicate the error.
|
---|
| 58 | .SH ERRORS
|
---|
| 59 | .B Fork
|
---|
| 60 | will fail and no child process will be created if one or more of the
|
---|
| 61 | following are true:
|
---|
| 62 | .TP 15
|
---|
| 63 | [EAGAIN]
|
---|
| 64 | The system-imposed limit on the total
|
---|
| 65 | number of processes under execution would be exceeded.
|
---|
| 66 | This limit is configuration-dependent.
|
---|
| 67 | (The kernel variable NR_PROCS in <minix/config.h> (Minix), or
|
---|
| 68 | <minix/const.h> (Minix-vmd).)
|
---|
| 69 | .TP 15
|
---|
| 70 | [ENOMEM]
|
---|
| 71 | There is insufficient (virtual) memory for the new process.
|
---|
| 72 | .SH "SEE ALSO"
|
---|
| 73 | .BR execve (2),
|
---|
| 74 | .BR wait (2).
|
---|