Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Nov 2003 04:27:27 -0800
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Peter Wemm <peter@wemm.org>
Cc:        current@freebsd.org
Subject:   Re: fork speed vs /bin/sh
Message-ID:  <3FC73F2F.47E7D488@mindspring.com>
References:  <20031127190413.6E8152A8FC@canning.wemm.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Wemm wrote:
> What this shows is that vfork() is 3 times faster than fork() on static
> binaries, and 9 times faster on dynamic binaries.  If people are
> worried about a 40% slowdown, then perhaps they'd like to investigate
> a speedup that works no matter whether its static or dynamic?  There is
> a reason that popen(3) uses vfork().  /bin/sh should too, regardless of
> whether its dynamic or static.  csh/tcsh already uses vfork() for the
> same reason.

I'm a big fan of vfork(); the on problem I have with the use of
it is that people tend to treat it as "a faster fork()", when it
definitely is not.  The utility of vfork() is limited to the list
of allowed system calls, which are _exit() and execve(); all other
usage is undefined -- specifically, you cannot control things like
whether it's the parent or the child that gets effected by calls
like setsid(), setpgrp(), etc..

The other place that vfork() really sucks is in applications like
"screen" or other applications that have multiple children and act
as mux'es for them: during the vfork() to spawn off a new child
from the parent, the parent is stalled, and this in turn stalls
all the children, as well.

The vfork() system call is a good thing, particularly compared to
the fork() system call, IFF it's used appropriately.

For the most part, FreeBSD should consider creating a posix_spawn()
system call, instead, for most uses to which people put either the
fork() or vfork() system calls today.

-- Terry



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3FC73F2F.47E7D488>