[svlug] Reuse of pid's.
Brian J. Tarricone
bjt23 at cornell.edu
Thu Jan 22 20:31:54 PST 2009
On Thu, 22 Jan 2009 18:08:44 -0800 Chris Miller wrote:
> IIRC, process forking is somewhat slow in Linux (as opposed to
> threading, which is entirely different and much faster).
Nope. Fork on Linux is actually a very fast operation, much faster
than on many other OSes (Windows and other UNIXes and BSDs
included). Linux uses copy-on-write when forking, so the only thing it
has to do is create a new task struct and copy the parent's page tables.
Actually, for several versions now, glibc doesn't even use the fork
system call anymore when you call fork(). It uses the clone system
call, thus making fork() just a special case of creating a new thread.
(Though I don't remember exactly; this might only be true when you link
your program with -lpthread.)
 To be fair, Windows doesn't have fork(), but CreateProcess() works
analogously to fork()+exec().
More information about the svlug