为什么禁止使用叉子没有在Mac EXEC? [英] Why is it prohibited to use fork without exec in mac?

查看:367
本文介绍了为什么禁止使用叉子没有在Mac EXEC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单。
在Linux上颇为流行用叉不EXEC

My question is quite simple. On Linux it is quite popular to use fork without exec

不过,我发现,在MacOS这是不可能的(见叉手册)

However, I have found that on MacOS this is not possible (see fork manual)

<一个href=\"https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fork.2.html\">https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/fork.2.html

是有限制的,你可以在子进程做什么。为了完全安全的,你应该限制你的自我自己
       自只执行异步信号安全的操作,直到时间的Exec功能之一是
       调用。所有API,包括全球数据符号,在任何框架或库应当被假定为
       一个fork()的,除非明确记载是安全的或异步信号安全不安全之后。如果您需要使用
       在子进程这些框架,您必须EXEC键。在这种情况下是合理的exec的自己。

There are limits to what you can do in the child process. To be totally safe you should restrict your-self yourself self to only executing async-signal safe operations until such time as one of the exec functions is called. All APIs, including global data symbols, in any framework or library should be assumed to be unsafe after a fork() unless explicitly documented to be safe or async-signal safe. If you need to use these frameworks in the child process, you must exec. In this situation it is reasonable to exec yourself.

这似乎很奇怪给我吗?是什么原因?是否有可能要解决它?

This seems strange to me? What is the reason? Is it possible to workaround it?

推荐答案

这没关系使用OS X叉,下您将使用叉Linux的同样的限制。 Linux的也有类似的的。

It's okay to use fork in OS X, under the same restrictions you would use fork with Linux. Linux has similar caveats.

如果您正在构建的应用程序是单线程的,并依赖于UNIX核心API和设计理念,你应该罚款。如果您链接到其他库,你应该非常熟悉他们的行为。想象一下,链接到启动一个后台线程库 - 分叉你会成为一个潜在的不确定状态后,只给出了所谓的叉克隆线程

If you are building an application that is single-threaded and relies on core UNIX APIs and design philosophy, you should be fine. If you are linking to additional libraries, you should be intimately familiar with their behavior. Imagine linking to a library that started a background thread – after forking you'd be in a potentially undefined state, given only the thread that called fork is cloned.

OS X提供了一些真棒功能,采取多个核心优势,如大中央调度这可能是值得考虑的。

OS X offers some awesome features for taking advantage of multiple cores, such as Grand Central Dispatch that may be worth considering.

我建议你阅读本文由Mike灰下OS X叉安全。

I'd recommend you read this article by Mike Ash on fork safety under OS X.

这篇关于为什么禁止使用叉子没有在Mac EXEC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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