mirror of https://github.com/mkerrisk/man-pages
98 lines
3.2 KiB
Groff
98 lines
3.2 KiB
Groff
.\" Hey Emacs! This file is -*- nroff -*- source.
|
|
.\"
|
|
.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
|
|
.\"
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
.\" preserved on all copies.
|
|
.\"
|
|
.\" Permission is granted to copy and distribute modified versions of this
|
|
.\" manual under the conditions for verbatim copying, provided that the
|
|
.\" entire resulting derived work is distributed under the terms of a
|
|
.\" permission notice identical to this one.
|
|
.\"
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume no
|
|
.\" responsibility for errors or omissions, or for damages resulting from
|
|
.\" the use of the information contained herein. The author(s) may not
|
|
.\" have taken the same level of care in the production of this manual,
|
|
.\" which is licensed free of charge, as they might when working
|
|
.\" professionally.
|
|
.\"
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
.\"
|
|
.\" Modified by Michael Haardt (michael@moria.de)
|
|
.\" Modified Sat Jul 24 13:22:07 1993 by Rik Faith (faith@cs.unc.edu)
|
|
.\" Modified 21 Aug 1994 by Michael Chastain (mec@shell.portal.com):
|
|
.\" Referenced 'clone(2)'.
|
|
.\" Modified 1995-06-10, 1996-04-18, 1999-11-01, 2000-12-24
|
|
.\" by Andries Brouwer (aeb@cwi.nl)
|
|
.\" Modified, 27 May 2004, Michael Kerrisk <mtk-manpages@gmx.net>
|
|
.\" Added notes on capability requirements
|
|
.\"
|
|
.TH FORK 2 2004-05-27 "Linux 2.6.6" "Linux Programmer's Manual"
|
|
.SH NAME
|
|
fork \- create a child process
|
|
.SH SYNOPSIS
|
|
.B #include <sys/types.h>
|
|
.br
|
|
.B #include <unistd.h>
|
|
.sp
|
|
.B pid_t fork(void);
|
|
.SH DESCRIPTION
|
|
.BR fork ()
|
|
creates a child process that differs from the parent process only in its
|
|
PID and PPID, and in the fact that resource utilizations are set to 0.
|
|
File locks and pending signals are not inherited.
|
|
.PP
|
|
Under Linux,
|
|
.BR fork ()
|
|
is implemented using copy-on-write pages, so the only penalty that it incurs
|
|
is the time and memory required to duplicate the parent's page tables,
|
|
and to create a unique task structure for the child.
|
|
.SH "RETURN VALUE"
|
|
On success, the PID of the child process is returned in the parent's thread
|
|
of execution, and a 0 is returned in the child's thread of execution. On
|
|
failure, a \-1 will be returned in the parent's context, no child process
|
|
will be created, and
|
|
.I errno
|
|
will be set appropriately.
|
|
.SH ERRORS
|
|
.TP
|
|
.B EAGAIN
|
|
.BR fork ()
|
|
cannot allocate sufficient memory to copy the parent's page tables and
|
|
allocate a task structure for the child.
|
|
.TP
|
|
.B EAGAIN
|
|
It was not possible to create a new process because the caller's
|
|
.B RLIMIT_NPROC
|
|
resource limit was encountered.
|
|
To exceed this limit, the process must have either the
|
|
.BR CAP_SYS_ADMIN
|
|
or the
|
|
.BR CAP_SYS_RESOURCE
|
|
capability.
|
|
.TP
|
|
.B ENOMEM
|
|
.BR fork ()
|
|
failed to allocate the necessary kernel structures because memory is tight.
|
|
.SH "CONFORMING TO"
|
|
The
|
|
.BR fork ()
|
|
call conforms to SVr4, SVID, POSIX, X/OPEN, 4.3BSD.
|
|
.SH EXAMPLE
|
|
See
|
|
.BR pipe (2)
|
|
and
|
|
.BR wait (2).
|
|
.SH "SEE ALSO"
|
|
.BR clone (2),
|
|
.BR execve (2),
|
|
.BR setrlimit (2),
|
|
.BR unshare (2),
|
|
.BR vfork (2),
|
|
.BR wait (2),
|
|
.BR capabilities (7)
|