fork Cocoa 进程并重新初始化 Cocoa。如何?
我尝试 fork()
一个 Cocoa 进程并设置一个新的 Cocoa/ObjC 环境,但出现错误:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
有没有办法在分叉进程中重新初始化 Cocoa/ObjC?
我知道有关 fork() 的文档确实说它是有限的,但是我想知道是否还有办法做到这一点,而不仅仅是文档所说的。
我尝试阅读 处理 execve 系统调用的 XNU 内核的源代码(bsd/kern/kern_exec.c) 但我不太习惯这些代码,所以我不能轻易地说它是否可能是否在用户空间中执行类似的操作。
I tried to fork()
a Cocoa process and setup a new Cocoa/ObjC environment but I get the error:
The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec().
Break on __THE_PROCESS_HAS_FORKED_AND_YOU_CANNOT_USE_THIS_COREFOUNDATION_FUNCTIONALITY___YOU_MUST_EXEC__() to debug.
Is there a way to re-initialize Cocoa/ObjC in the forked process?
I know that the documentation about fork()
does say it is limited, however I wonder if there is still a way to do it, not just what the documentation says.
I tried to read the source code of the XNU kernel which handles the execve syscall (bsd/kern/kern_exec.c) but I am not that used to the code that I cannot easily say wether it is possible or not to do something similar in userspace or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mac OS X 严重限制了您在 fork 后无需执行即可执行的操作。请参阅 fork man 的“注意事项”部分页面。允许的操作不包括使用 Cocoa 或 CoreFoundation,因此您必须调用 exec 来启动新程序。
Mac OS X severely limits what you can do after a fork without
exec
ing. See the CAVEATS section of the fork man page. The allowed actions do not include using Cocoa or CoreFoundation, so you must callexec
to start a new program.