Re: Can you pass a file descriptor to another process?
Re: Can you pass a file descriptor to another process?
- Subject: Re: Can you pass a file descriptor to another process?
- From: Mark Day <email@hidden>
- Date: Wed, 20 Aug 2014 15:26:26 -0700
Possible, yes. How to do it depends on how you're communicating with your helper process.
The recommended way is to use XPC to communicate with your helper. When you send a message using XPC, you can put a file descriptor into the message using xpc_dictionary_set_fd. On the receiving end, you use xpc_dictionary_dup_fd. A nice aspect of XPC is that it will automatically launch your helper when you attempt to send it a message (and it's not already running). It does mean that your helper has to have a run loop (XPC provides xpc_main if you don't have a CF or Foundation run loop). If your helper wants to communicate progress back to the main process, that's easy, too: the XPC connection is bi-directional, so the helper can send messages to the main process.
-Mark
> On Aug 20, 2014, at 1:49 PM, James Bucanek <email@hidden> wrote:
>
> Random question of the week: Is it possible in OS X/Darwin to use ioctl() and the I_SENDFD/I_RECVFD commands to copy a file descriptor to another process?
>
> I have a helper process that's started (indirectly) via launchd. I'm now writing a command line tool to control it. At some point I'd like to redirect the helper's output to the file descriptor of the tool's stdout/stderr. In other words, I want to command line tool to tell the the helper to do something useful, and then have the helper's output sent to the same stdout the tool is connected to.
>
> A little research says this should be possible using ioctl() and the I_SENDFD and I_RECVFD commands, but I cannot find these command symbols in the OS X frameworks. (Well, there's one in OpenTransportProtocol.h, but I'm pretty sure we're not supposed to be using that.)
>
> So let me start by asking if this is even possible in OS X/Darwin.
>
> James
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden