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: Any caveats to using fork in a Foundation/CoreFoundation tool?



Hi Jim,

On Oct 25, 2007, at 9:45 AM, Jim Correia wrote:

I have the need to launch a tool from my GUI application that needs to be in its own process group (i.e. the parent process should not be the GUI app which launched it, since it needs to outlive the parent process.)

It will use CFMessagePort to communicate with the parent app.

I seem to recall that using fork not followed immediately by exec was a bad idea for Foundation/CoreFoundation tools or applications, but at the moment I can't find those references in the archives.

Perhaps these messages will be easier to find.

Is using fork (or daemon, as the case may be) at the top of main going to cause me grief when I want to later use Foundation or CoreFoundation services?

Yes. :)

Any other recommended approaches?

Using launchd or LaunchServices is really the way to go here; go ahead and use CFMessagePort for your IPC, but either use a launchd plist to start your non-GUI process on-demand, or have your GUI process use LaunchServices to fire it up.


In order for all the CF/Foundation internals to be initialized properly, an exec() has to happen otherwise things won't work, or won't work the way you expect (especially Mach-based things, like CFMessagePort).

The "Agents and Daemons" technote talks about using launchd:

	http://developer.apple.com/technotes/tn2005/tn2083.html

Having LaunchServices is a way of asking someone else to do the launch for you.

Either way, the non-GUI bits will wind up not being in the parent's process group.

.chris

--
Chris Parker
Cocoa Frameworks
Apple Inc.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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/email@hidden

This email sent to email@hidden
References: 
 >Any caveats to using fork in a Foundation/CoreFoundation tool? (From: Jim Correia <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.