Hello -
Reading Advanced Programming in the UNIX Environment by Richard W. Stevens, I see that
he says that vfork() should be used instead of fork() when you just need to use one of
the exec() functions, since it doesn't need to fully copy the address space.
Later in the book, he has an example system() which uses fork() to run /bin/sh -c via
the execl() function.
Why wouldn't he use vfork() instead of fork()?
I ran FreeBSD's version of system() both by the default (using fork()) and by using
vfork()
I ran a loop 1000 times that called system("echo");
Here are my results:
time ./app
fork() vfork()
1. 4.528 3.056
0.050 0.058
2.078 1.492
2. 3.652 2.865
0.060 0.060
2.036 1.484
3. 3.735 3.022
0.068 0.041
2.031 1.506
As you can see, vfork() performed better.
But, I am sure there is good reasoning for using fork() over vfork() in the system()
call, and I am just curious why.
Can anyone explain this?
Thanks
- David
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message