Re: Porting vfork()

Richard B. Johnson (root@chaos.analogic.com)
Thu, 7 Jan 1999 15:47:14 -0500 (EST)


On 7 Jan 1999, H. Peter Anvin wrote:

> Followup to: <19990105154611.A16497@draper.net>
> By author: kernel@draper.net
> In newsgroup: linux.dev.kernel
> >
> > So, the question: is linux vfork() behavior annoying anyone else and is it
> > worth fixing? (other than to eliminate its appearance in the BUG area of the
> > Linux fork() man page ;)
> >
>
> I think you can mimic the BSD vfork() at the library level by using
> clone() and perhaps trapping exec().
>
> -hpa
> --

It this necessary? If vfork() is being used for its side-effects the
program is buggy. Here is a copy of Sun's man-page with non pertainent
stuff edited out.

This is from Sun's man-page

DESCRIPTION
vfork() can be used to create new processes without fully
copying the address space of the old process. It is useful
when the purpose of fork() would have been to create a new
system context for an execve(). vfork() differs from fork()
in that the child borrows the parent's memory and thread of
control until a call to execve() or an exit (either by a
call to _exit() (see exit(2)) or abnormally). The parent
process is suspended while the child is using its resources.
In a multi-threaded application, vfork() borrows only the
thread of control which called vfork() in the parent; that
is, the child contains only one thread. In that sense, in a
multi-threaded application vfork() behaves like fork().

vfork() is unsafe in multi-thread applications.

This function will be eliminated in a future release. The
memory sharing semantics of vfork() can be obtained through
other mechanisms.

On some systems, the implementation of vfork() causes the
parent to inherit register values from the child. This can
create problems for certain optimizing compilers if
<unistd.h> is not included in the source calling vfork().

-----------

If vfork() is being used so the child can write to the parent's
memory, it is a bug pure and simple. Linux's implementation
that uses fork() for vfork() because we are efficient and do
copy-on write, prevents continuing this side-effect abuse.

Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.1.131 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.
Wisdom : It's not a Y2K problem. It's a Y2Day problem.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/