Infodoc ID |
|
Synopsis |
|
Date |
4820 |
|
Understanding the differences between fork and vfork |
|
16 Nov 1995 |
The vfork() function call can be dangerous to use if not well
understood.
Internally, vfork() and fork() are completely different
routines. fork() duplicates the address space of the
existing process and thus creates an identical, yet
entirely separate child process. vfork() merely passes
its address space to the child.
Although fork is often described as "inefficient", it is
"safe" to use. Note that fork() must allocate and fill
in proc, user and swap structures, allocate kernel and
user page tables, allocate another kernel stack and copy
the contents of stack and data pages-excluding the
fill-on-demand page table entries. For big processes,
this is expensive. However, two independent processes
exist. The child initiates its execution andthe parent
resumes its execution.
vfork() allocates new proc and user structures, but most
significantly, the contents of the stack, text and data
segments are not copied, but rather their addresses are
passed through the user and proc structs. If an exec()
or exit() call is issued there after, a new text, stack
and data segments are allocated for the child and the
parent resumes execution. If vfork() is used strictly in
this sense, the vfork() routine is more efficient.
However, an architectural quirk exists with vfork().
Before the child calls exec() or exit(), the child may
alter the contents of the parents address space.
Top
Sun Proprietary/Confidential: Internal Use Only
Feedback to SunSolve Team