• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: GDB: Does "catch vfork" work?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GDB: Does "catch vfork" work?


  • Subject: Re: GDB: Does "catch vfork" work?
  • From: "Justin C. Walker" <email@hidden>
  • Date: Sun, 9 Oct 2005 08:07:47 -0700

My 0.016 Euros:

On Oct 9, 2005, at 06:51 , Jim Correia wrote:

On Oct 8, 2005, at 6:55 AM, Damien Bobillot wrote:


If you use fork, the whole parent memory is copied.


There is no reason the kernel could't (or doesn't) use copy on write semantics for fork, AFAIK. Whether or not it actually does it is another question.

It does use copy-on-write semantics. In fact, for reasons that escape me, from NextStep on, COW was "architectural", rather than an implementation detail.


If you use vfork, the memory is lazily copied : the system wait until it really need to make the copy, ie if both processes don't write anything in a given memory page, the system won't make the copy, but if one do write something, the system make the copy just before effectively writing things. This use the copy-on-write flag of the paged memory manager.

The only difference between fork and vfork is that vfork is more efficient : for the developer, even when debugging, both functions seem to work the same way.


Again, I'm not a complete expert on the topic, but my understanding is that vfork does not use copy on write semantics, but rather shares the parent's address space until the exec. If you do anything after the fork and before the exec you are making changes in the parent's address space (and they are probably unexpected changes from the parent's POV.) My experience is consistent with this. (In other words, I believe the man page to be correct.)

This is the difference between fork() and vfork(): in the former, the child runs in a copy of the parent's address space (whether the copy is ever completed is a detail); in the latter, the child uses the parent's address space.


This was a "hack" made at a time when copy-on-write had either not been invented, or was not possible on much of the hardware (i.e., pdp-11's) in use. The intent was to speed up the typical fork()/exec () sequence by avoiding the copy of the process space.

Regards,

Justin

--
Justin C. Walker, Curmudgeon-At-Large
Institute for General Semantics
--------
Men are from Earth.
Women are from Earth.
   Deal with it.
--------


_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: GDB: Does "catch vfork" work?
      • From: Daniel Jalkut <email@hidden>
References: 
 >GDB: Does "catch vfork" work? (From: Daniel Jalkut <email@hidden>)
 >Re: GDB: Does "catch vfork" work? (From: Damien Bobillot <email@hidden>)
 >Re: GDB: Does "catch vfork" work? (From: Daniel Jalkut <email@hidden>)
 >Re: GDB: Does "catch vfork" work? (From: Damien Bobillot <email@hidden>)
 >Re: GDB: Does "catch vfork" work? (From: Jim Correia <email@hidden>)

  • Prev by Date: Re: GDB: Does "catch vfork" work?
  • Next by Date: Re: GDB: Does "catch vfork" work?
  • Previous by thread: Re: GDB: Does "catch vfork" work?
  • Next by thread: Re: GDB: Does "catch vfork" work?
  • Index(es):
    • Date
    • Thread