与子进程共享Mach端口 [英] Sharing Mach ports with child processes

查看:84
本文介绍了与子进程共享Mach端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在比较Mac OS X上可用的不同IPC机制(管道,套接字,System V IPC等),并且我想看看Mach端口与更高级别的替代品的比较.但是,我遇到了一个非常基本的问题:跨进程(尤其是跨父进程和子进程)获取端口的发送权限.

I am doing a comparison of different IPC mechanisms available on Mac OS X (pipes, sockets, System V IPC, etc.), and I would like to see how Mach ports compare to the higher-level alternatives. However, I've run into a very basic issue: getting send rights to ports across processes (specifically, across a parent process and a child process).

与文件描述符不同的是,端口通常不会转移到分支流程.这意味着必须建立其他传输方式.我可以找到的唯一与此相关的页面是此页面,并且他们在更新中指出,即使该方法

Unlike file descriptors, ports are generally not carried over to forked processes. This means that some other way to transfer them must be established. Just about the only relevant page I could find about this was this one, and they state in an update that their method no longer works and never was guaranteed to, even though that method was suggested by an Apple engineer in 2009. (It implied replacing the bootstrap port, and now doing that breaks XPC.) The replacement they suggest uses deprecated functions, so that's not a very appealing solution.

此外,我喜欢旧解决方案的一件事是端口在使用它的进程之间仍然非常私有.不需要广播端口的存在,就像管道(来自pipe调用)一旦分叉就可以工作一样. (如果还有其他解决方案,我可能会接受,但这有点烦人.)

Besides, one thing I liked about the old solution is that ports remained pretty much private between the processes that used it. There was no need to broadcast the existence of the port, just like pipes (from the pipe call) work once forked. (I'll probably live with it if there's another solution, but it's a little annoying.)

那么,如何从父进程向子进程传递对Mach端口的发送权限?

So, how do you pass a send right to a Mach port from a parent process to a child process?

推荐答案

bootstrap_register已被弃用,但bootstrap_check_in却不被使用,可用于注册您的端口,稍后子进程可以使用bootstrap_look_up. (不幸的是,这仍然不能提供您想要的隐私).

bootstrap_register is deprecated but bootstrap_check_in isn't, and can be used to register your port which can later be retrieved by the child process by using bootstrap_look_up. (This still doesn't provide the privacy you're looking for, unfortunately).

这篇关于与子进程共享Mach端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆