fork function is the primitive for creating a process.
It is declared in the header file `unistd.h'.
forkfunction creates a new process.
If the operation is successful, there are then both parent and child
processes and both see
fork return, but with different values: it
returns a value of
0 in the child process and returns the child's
process ID in the parent process.
If process creation failed,
fork returns a value of
the parent process. The following
errno error conditions are
RLIMIT_NPROCresource limit, which can usually be increased; see section Limiting Resource Usage.
The specific attributes of the child process that differ from the parent process are:
vforkfunction is similar to
forkbut on systems it is more efficient; however, there are restrictions you must follow to use it safely.
fork makes a complete copy of the calling process's
address space and allows both the parent and child to execute
vfork does not make this copy. Instead, the
child process created with
vfork shares its parent's address
space until it calls exits or one of the
exec functions. In the
meantime, the parent process suspends execution.
You must be very careful not to allow the child process created with
vfork to modify any global data or even local variables shared
with the parent. Furthermore, the child process cannot return from (or
do a long jump out of) the function that called
would leave the parent process's control information very confused. If
in doubt, use
Some operating systems don't really implement
vfork. The GNU C
library permits you to use
vfork on all systems, but actually
vfork isn't available. If you follow
the proper precautions for using
vfork, your program will still
work even if the system uses
Go to the first, previous, next, last section, table of contents.