Le 31 juil. 2011 à 09:27, Ron Hunsinger a écrit :

> When a process forks, the child and parent get different virtual memory maps 
> that, for the time being, happen to point to the same physical memory pages. 
> The sharing is an implementation detail, for optimization. Conceptually, the 
> parent's memory is copied into the child's memory space, so that if one of 
> the processes modifies the "shared" memory, the other process does not see 
> the change. The implementation, under the hood, does copy-on-write so that 
> the cost of that copying can be deferred until needed. Since fork is usually 
> followed by exec in the child, the copying usually never takes place, so it's 
> a particularly good optimization. Don't be misled into thinking that just 
> because the copying is deferred that the parent and child are actually 
> sharing a single virtual memory space.

Thanks for these precisions. Actually, you’re right with fork (2), but vfork 
(2), AFAIK, does not copy anything; note that I’m aware that vfork usually is 
meant to be immediately followed by exec (3).

> The other methods you mention of sharing memory are by special arrangement, 
> and rarely used (although extremely useful when they are).

I agree also. My point was to mitigate the statement that processes cannot 
share common memory. Of course, as you mentioned, in normal operation they 
don’t: That’s, after all, the whole point of the MMU, applications live in a 
memory sandbox. As far as I remember, wasn’t it D. Ritchie who related that, 
when developing on old PDP11/70, it was customary to yell "a.out !" when you 
were about to launch a program, because it gave others time to save their work 
before a possible general crash or data corruption? 

Vincent


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to