Re: Mac OS Leopard: how to spawn an child "application"?
Re: Mac OS Leopard: how to spawn an child "application"?
- Subject: Re: Mac OS Leopard: how to spawn an child "application"?
- From: Ken Thomases <email@hidden>
- Date: Sat, 11 Jun 2011 12:39:08 -0500
On Jun 11, 2011, at 11:59 AM, Nick wrote:
> i have an agent and a corresponding per-agent process (this per-agent process, apart from doing its main job and displaying gui when its clicked, displays an icon in dock which can change colors). Of course, the agent is spawned for every logged in user.
You should consider reversing the relationship between the agent and the GUI app. Consider making your agent a launchd agent, which is launched on demand whenever the GUI app requests its services (or when some other launchd-supported event occurs). To the GUI app, it appears as though the agent is always available.
> I found parent-child connected (socketpair) sockets/pipes to be the easiest way to set up a conversation between an agent and that peruser application in Dock. And in Snow Leopard it works.
If it works in Snow Leopard, it's by accident and likely to fail in configurations you haven't thought to test or in future OS releases. You should be using Launch Services to launch applications.
> This "per user" idea does not let me use any advertisement-based IPCs (like user domain sockets or bonjour).
Unix domain sockets can be in user-specific locations within the file system, like the temporary directory.
> I need some "per user only" IPC - so other user's instance of the process does not interfere with the current user's one.
>
> I've heard that Mach Ports can be set to be seen only in the current login session (i.e., by current user's apps), but search led me to conclusion this is rather a messy/few documented (for usermode applications) topic and it behaves differently for Leopard and Snow Leopard due to some changes in "bootstrap context"
You don't have to use raw Mach ports. You can use CFMessagePort or NSMachPort. If you're thinking of TN2083 <http://developer.apple.com/library/mac/#technotes/tn2083/>, there are recommendations against Mach-port-based APIs but they're only in regards to daemons, not agents, precisely because daemons are non-user-specific. For agents, they are appropriate. (See the "IMPORTANT" note just above the "Mach Considered Harmful" section.)
You should consider Distributed Objects, or at least the techniques it uses with NSConnection and NSPort-derived objects. See the Distributed Objects Programming Topics <http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DistrObjects/DistrObjects.html>. If you aren't comfortable using it for the bulk of your IPC, maybe it will just be useful to exchange the name of a Unix domain socket between the server and the client.
Regards,
Ken
_______________________________________________
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:
This email sent to email@hidden