Re: fork ???

> 	From the fork() man page:
> [...]
>        Under Linux, vfork is merely an alias for fork.

That's no longer true.  On Linux since 2.2.0-pre9 (on i386)
vfork is  an  independent system call (somewhat later on other architectures),
implemented to handle (old) code that uses vfork().

In general: don't use vfork(), use fork().  vfork() is full of traps
for the unwary. For example, from the man page:
       the  behaviour
       is undefined if the process created by vfork() either modifies
       any data other than a variable of type pid_t used to
       store  the  return value from vfork()...
That data includes "hidden" data modified by the C compiler (like temporary
variables used internally by the compiler for processors like x86s with few
registers).  So, to be SURE your code will work you have to know
or examine the assembly code generated by the version of the
compiler you're using for each processor you're using :-(.
Thankfully, typical code usually "happens to
work", but who needs this kind of grief?  Then there's weirdnesses
involving signals, shared memory, failed execs, etc.

vfork() is an old performance hack for systems without copy-on-write;
with today's systems it's usually not worth the potential reliability problems.

My man page of vfork(2) says:
       It is rather unfortunate that Linux revived  this  spectre
       from  the past.


--- David A. Wheeler

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]