Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about mach ports and fork



On Jan 21, 2004, at 3:37 PM, Nathan T. Hjelm wrote:
I have tried to open a new connection to iokit with the child process by
calling IOCreateMasterPort again but I get the same result as when I
didn't. The problem must lie in the IOService which looks like it keeps
trak of the master port used to open it. It would be a really simple fix
if i could rely on the programmer to call usb_open on a device after the
fork call (i think. i know there are a number of ports invalidated that I
don't really know about).

After fork()ing the memory image is stale (i.e. contain names for Mach ports that the child doesn't actually have). One could argue that all these frameworks should install atfork() handlers and clean up this state. The problem is that it is not really possible to determine the order those handlers have to be called in in order to assure all dependencies are met (the spec says they are called in the same order that they are registered, but the order required to "re-initialize" the frameworks may be quite different than the order to initialize them the first time). So, we haven't gone that route (except for the basic Un*x libraries).

Instead, you MUST exec() after fork() in any process that is using any Mac OS X-specific frameworks. You can re-exec the same executable - and pass a parameter to indicate that it has already fork()'ed and doesn't need to again. If you do this, you will re-initialize correctly.

--Jim
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.

References: 
 >question about mach ports and fork (From: "Nathan T. Hjelm" <email@hidden>)
 >Re: question about mach ports and fork (From: Jim Magee <email@hidden>)
 >Re: question about mach ports and fork (From: "Nathan T. Hjelm" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.