Re: vfork()

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

 



Exactly right...i mistaken wrote that its a *combination* of fork() and exec(), the difference between vfork() and fork() is simply that since most of the call sequence involving fork() and exec() is like this

if (! fork ())
exec (...);

It means that as soon as a child is forked, the next step is to replace its address space with that of the executable in exec(). So the step of actually copying the address spaces of parent into child is useless and uneccessary overhead, this extra copying is prevented in the call vfork().

Hence fork() can be used where vfork() is used, with an overhead, but simply calling vfork() without an exec is useless.


Ketan


Javier Guerra wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

MAASK Group wrote:

Vfork is a combination of fork() and exec().
I am confused. The programmer explicitly has to call exec() after a
vfork(). right?

right, vfork() isn't a combination of fork() and exec(), more exactly, it's a
version of fork() to be used only when immediatly followed by a exec()
so, instead of writing

	if (! fork ())
		exec (...);

you could write

	if (! vfork ())
		exec (...);

and avoid the copying of the process segment that would be overwritten by
exec().  in modern OSs, the process is marked copy-on-write, so it's just as
fast, without the restrictions.  that's why it's man page tells you not to
use it anymore.

- ------
Javier
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+Rn3HsIoGnxsRK/ERAmzmAJ0YLEju/TRGLnX8asM3vEN/MgMVXQCgpdUL
B4WhKo2sgxVbxDkGq/QPbLo=
=Bxlb
-----END PGP SIGNATURE-----

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



--

Marriage is the triumph of imagination over intelligence.
Second marriage is the triumph of hope over experience.

	

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux