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 process:
o Environment
o Close-on-exec flags
o Signal handling settings
o Set user ID mode bit
o Set group ID mode bit
o Trusted state
o Profiling on/off status
o Nice value
o All attached shared libraries
o Process group ID
o tty group ID
o Current directory
o Root directory
o File mode creation mask
o File size limit
o Attached shared memory segments
o Attached mapped file segments
o All mapped regions with the same protection and sharing
mode as in the parent process
o Its own copy of the parent's open directory streams
The child process differs from the parent process in the
following ways:
o The child process has a unique process ID and does not
match any active process group ID.
o The parent process ID of the child process matches the
process ID of the parent.
o 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.
o All semadj values are cleared.
o Process locks, text locks, and data locks are not
inherited by the child process.
o The child process's utime(), stime(), cutime(), and
cstime() are set to 0 (zero).
o Any pending alarms are cleared in the child process.
o Any interval timers enabled by the parent process are
disabled in the child process.
o Any signals pending for the parent process are disabled
for the child process.
If a multithreaded process calls the fork() function, the
new process contains a replica of the calling thread and its
entire address space, possibly including the states of
mutexes and other resources. Consequently, to avoid errors,
the child process may only execute operations it knows will
not cause deadlock until such time as one of the exec func-
tions is called.
NOTES
The fork() function is supported for multi-threaded applica-
tions.
The vfork() function is supported as a compatibility inter-
face for older BSD system programs, and can be used by com-
piling with Berkeley Compatibility Library (libbsd.a). The
memory sharing semantics of the vfork() function 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 pro-
cess 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 indicate 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 executing 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)
Acknowledgement and Disclaimer