Sorry, real life interfered with my ability to participate in a timely
manner...
>>>> "JV" == Justin Vallon
<vallon(a)mindspring.com> writes:
JV> On Wed, 4 Nov 1998, Georg Nikodym wrote:
> When a UNIX process wants to create a child, it fork()s and
> exec()s. The fork() duplicates the parent's address space. This
> was seen as silly when 9 times out of 10 the child simply calls
> exec and thus was born vfork(). vfork() has this problem, though
> that the child briefly runs in the parents address space. The
> implications of this statement are serious and have resulted in
> two things. First, standards authors have had no choice but to
> say that you can't guarantee anything aside from exec() or _exit()
> will work. Second, application developers have been bitten by all
> kinds of nasty bugs and have shied away from vfork. The net
> result is that vfork() could probably be removed from the UNIX ABI
> and nobody would shed a tear.
JV> I don't believe this is the case. While fork() does duplicate
JV> the address space, it does not have to physically duplicate the
JV> memory used by the process. First, mapped files (the executable,
JV> shared libs) are read-only and thus can be shared. Also, most
JV> modern OSes will implement copy-on-write in this situation. The
JV> original memory image will be shared on a page-by-page basis
JV> until one process writes to the shared page. At that point, the
JV> page is duplicated.
Absolutely. But whether or not a physical page is copied into has no
bearing on the allocation of a virtual page.
JV> So, { fork(); exec(); } is a relatively efficient operation.
Duplicating an address space is not trivial. An SVR4 address space
(as) consists of a list of segments (seg) which each have a list of
page structures (page). So, in my 500MB+ XEmacs, there's still 62500
pages to be duplicated.
vfork does _no_ address space duplication. So to say that fork() is
not much more expensive is one of the convenient lies of
simplification for under qualified application programmers that later
become net.myth. (sorry wrong rant)
A number of you have raise the notion of over-commitment. I agree
that a case can be made here. However, the argument then distills
down to one of philosophy:
On the one hand you check to see that everything you could ever want
to do will be possible (ie, some minimal guarantee) and if not fail
early in such a way that the application can decide how to solve the
problem.
Or on the other hand, don't guarantee anything and create a situation
where an application can be shot randomly by the kernel if it
misbehaves.
The latter approach is seductive but has some serious problems.
The main one being the application programmers cannot protect or
harden themselves against this class of failure. To many commercial
software providers (ignoring any statements about the quality of their
stuff) this approach is untenable.
With AIX, IBM introduced SIGDANGER (a signal that will be fatally
delivered to random processes when the system is running out of
memory). The hue and cry in the industry drove IBM to make the
delivery of SIGDANGER optional. Nobody (here at least) wants to
repeat that bit of history.
Once again the real answer is to invent a new interface that actually
does what everybody wants and provides the safety guarantees the
everybody needs. Possible but hard, both technically and politically.
In the meantime, for the purposes of XEmacs, vfork on Solaris 2.6 and
up is safe.