Unix for Beginners
Unix Shell Programming
Advanced Unix
Unix Useful References
Unix Useful Resources
Selected Reading
Copyright © 2014 by tutorialspoint
|
fork() - Unix, Linux System Call
Advertisements
NAME
fork - create a child process
SYNOPSIS
#include <sys/types.h>
#include <unistd.h>
pid_t fork(void);
|
DESCRIPTION
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.
Under Linux, fork() is implemented using copy-on-write pages, so the only penalty that it incurs
is the time and memory required to duplicate the parents page tables,
and to create a unique task structure for the child.
RETURN VALUE
On success, the PID of the child process is returned in the parents thread
of execution, and a 0 is returned in the childs thread of execution. On
failure, a -1 will be returned in the parents context, no child process
will be created, and errno will be set appropriately.
ERRORS
Error Code | Description |
EAGAIN |
fork() cannot allocate sufficient memory to copy the parents page tables and
allocate a task structure for the child.
|
EAGAIN |
It was not possible to create a new process because the callers
RLIMIT_NPROC resource limit was encountered.
To exceed this limit, the process must have either the
CAP_SYS_ADMIN or the
CAP_SYS_RESOURCE capability.
|
ENOMEM |
fork() failed to allocate the necessary kernel structures because memory is tight.
|
CONFORMING TO
SVr4, 4.3BSD, POSIX.1-2001.
SEE ALSO
Advertisements
|
|
|