fork Cocoa process and re-init Cocoa. how?

巧了我就是萌 提交于 2019-12-01 10:38:21

问题


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.


回答1:


Mac OS X severely limits what you can do after a fork without execing. See the CAVEATS section of the fork man page. The allowed actions do not include using Cocoa or CoreFoundation, so you must call exec to start a new program.



来源:https://stackoverflow.com/questions/7379419/fork-cocoa-process-and-re-init-cocoa-how

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!