FORK(S) UNIX System V FORK(S)
Name
fork - create a new process
Syntax
int fork ()
Description
The fork system call causes creation of a new process. The
new process (child process) is an exact copy of the calling
process (parent process). This means the child process
inherits the following attributes from the parent process:
environment
close-on-exec flag (see exec(S))
signal handling settings (that is, SIG_DFL, SIG_IGN,
SIG_HOLD, function address)
set-user-ID mode bit
set-group-ID mode bit
profiling on/off status
nice value (see nice(S))
all attached shared memory segments (see shmop(S))
process group ID
tty group ID (see exit(S))
current working directory
root directory
file mode creation mask (see umask(S))
file size limit (see ulimit(S))
The child process differs from the parent process in the
following ways:
The child process has a unique process ID.
The child process has a different parent process ID
(that is, the process ID of the parent process).
The child process has its own copy of the parent's file
descriptors. Each of the child's file descriptors
shares a common file pointer with the corresponding
file descriptor of the parent.
All semadj values are cleared (see semop(S)).
Process locks, text locks, and data locks are not
inherited by the child (see plock(S)).
The child process's utime, stime, cutime, and cstime
are set to 0. The time left until an alarm clock
signal is reset to 0.
The fork system call fails and no child process is created
if one or more of the following is true:
[EAGAIN] The system-imposed limit on the total number
of processes under execution would be
exceeded.
[EAGAIN] The system-imposed limit on the total number
of processes under execution by a single user
would be exceeded.
[EAGAIN] Total amount of system memory available when
reading via raw I/O is temporarily
insufficient.
[EMFILE] The shared data table would overflow.
[ENOMEM] The process requires more space than the
system is able to supply.
See Also
exec(S), nice(S), plock(S), ptrace(S), semop(S), shmop(S),
signal(S), sigset(S), times(S), ulimit(S), umask(S), wait(S)
Diagnostics
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 errno is set to indicate the error.
Standards Conformance
fork is conformant with:
AT&T SVID Issue 2, Select Code 307-127;
The X/Open Portability Guide II of January 1987;
IEEE POSIX Std 1003.1-1988 with C Standard Language-
Dependent System Support;
and NIST FIPS 151-1.
(printed 6/20/89)