fork() system call
fork(2) fork(2)
NAME
fork, vfork - Creates a new process
SYNOPSIS
#include <sys/types.h>
pid_t fork ( void );
pid_t vfork ( void );
DESCRIPTION
The fork() and vfork() functions create a new process (child process) that
is identical to the calling process (parent process).
The child process inherits the following attributes from the parent pro-
cess:
+ Environment
+ Close-on-exec flags
+ Signal handling settings
+ Set user ID mode bit
+ Set group ID mode bit
+ Trusted state
+ Profiling on/off status
+ Nice value
+ All attached shared libraries
+ Process group ID
+ tty group ID
+ Current directory
+ Root directory
+ File mode creation mask
+ File size limit
+ Attached shared memory segments
+ Attached mapped file segments
+ All mapped regions with the same protection and sharing mode as in the
parent process
+ Its own copy of the parent's open directory streams
The child process differs from the parent process in the following ways:
+ The child process has a unique process ID and does not match any
active process group ID.
+ The parent process ID of the child process matches the process ID of
the parent.
+ The child process has its own copy of the parent process's file
descriptors. However, each of the child's file descriptors shares a
common file pointer with the corresponding file descriptor of the
parent process.
+ All semadj values are cleared.
+ Process locks, text locks, and data locks are not inherited by the
child process.
+ The child process's utime(), stime(), cutime(), and cstime() are set
to 0 (zero).
+ Any pending alarms are cleared in the child process.
+ Any interval timers enabled by the parent process are disabled in the
child process.
+ Any signals pending for the parent process are disabled for the child
process.
If a multithreaded process calls the fork() function, the new process con-
tains a replica of the calling thread and its entire address space, possi-
bly including the states of mutexes and other resources. Consequently, to
avoid errors, the child process should only execute operations it knows
will not cause deadlock until one of the exec functions is called.
NOTES
The fork() function is supported for multi-threaded applications.
The vfork() function is supported as a compatibility interface for older
BSD system programs, and can be used by compiling with Berkeley Compatibil-
ity Library (libbsd.a). The memory sharing semantics of the vfork() func-
tion are synonymous with the fork() function.
AES Support Level:
Full use (fork())
RETURN VALUES
Upon successful completion, the fork() function returns a value of 0 (zero)
to the child process and returns the process ID of the child process to the
parent process. If the fork() function fails, a value of -1 is returned to
the parent process, no child process is created, and errno is set to indi-
cate the error.
ERRORS
If the fork() function fails, errno may be set to one of the following
values:
[EAGAIN] The system-imposed limit on the total number of processes execut-
ing for a single user would be exceeded. This limit can be
exceeded by a process with superuser privilege.
[ENOMEM] There is not enough space left for this process.
RELATED INFORMATION
Functions: exec(2), exit(2), getpriority(2), getrusage(2), nice(3),
plock(2), ptrace(2), raise(3), semop(2), shmat(2), sigaction(2), sigvec(2),
times(3), ulimit(3), umask(2), wait(2) delim off