Post by G Gcreating a process in unix takes longer than in windows?
There aren't enough different implementations of Windows to make
interesting empirical results.
First of all, Windows does not offer fork (in its regular Win32
subsystems). So the following operation is very expensive:
Creating a process which is a replica of the invoking "parent"
process, executing the same point in the same function.
The Cygwin project implements this fork operation in plain Win32.
It's neither fast nor pretty.
If we have the following requirement:
Creating a process which runs a new process image specified
via a nominated executable program in the filesystem space,
which receives a new address space.
then for that, Windows has the CreateProcess family of functions,
whereas traditional unix has fork combined with an exec function.
CreateProcess is, overall, saddled with fewer expensive requirements;
since there is no fork, there is no address space copying, and since
there is no exec-in-place, there is no clean-up of an existing space.
Unix systems have historically optimized fork with lazy semantics
to make it faster for all its intended uses, including the exec
case, where laziness wins by avoiding up-front duplication of an address
space only to then replace it. Further optimized variants of fork also
appeared (vfork) which so optimized toward the exec case as to be
incorrect if used for any other purpose.
exec in Unix has to clean up various parent resources. An
exec-optimized fork can help here by minimizing the clean-up.
If the exec is done out of a vfork, it knows not to clean up
most of the resources, which would be wrong, since they are still shared
with the parent.
Furthermore, certain resources are passed to the new process image,
such as signal hangling dispositions (which signals are SIG_IGN or
SIG_DFL) and open file descriptors not marked close-on-exec.
An exec-optimized fork cannot do much here.
None of this is an issue for CreateProcess which makes a new address
space, not requiring any clean-up. There is a BOOL flag for whether open
handles are inherited by the new process, which we would set to FALSE
if we were benchmarking process creation. Signals don't exist.
Complicating the comparison is that POSIX now has a function called
posix_spawn, which in many ways resembles CreateProcess. It creates
a new process without the involvement of fork semantics, over a
specified executable program, and has arguments for controlling
inheritance of resources.
If we were benchmarking process creation in a modern Unix implementation
against Win32, of course it would behoove us to use posix_spawn.
--
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1