hjp: os: fork vs. vfork

fork vs. vfork

The linux man page of vfork(2) used to claim more or less that vfork is unneccessary for performance reasons because fork uses copy on write and is just as fast. The current version of the man-page on a Debian system is much more cautious and accedes that vfork "may be useful in performance sensitive applications".

Inspired by a thread in comp.lang.perl.misc I wrote a simple test program in C. Here are the results (for Linux 2.6.26/686 on a 1.86 GHz Intel Core2 with 1GB RAM):

fork vs. vfork times
[fork times] [vfork times]

So fork is actually quite a lot slower than vfork for large processes (about 800 times for the 400 MB case) and the absolute time (32 milliseconds for the 400 MB case) may not be negligible for some applications.

$Date$