macos Mac OS X 和 BSD 的关系有多密切?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3446231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How closely are Mac OS X and BSD related?
提问by Boolean
I read that Mac OS X and bsd are related. How closely are they related. Can Mac OS X software be tweaked and installed on BSD?
我读到 Mac OS X 和 bsd 是相关的。他们的关系有多密切。可以在 BSD 上调整和安装 Mac OS X 软件吗?
回答by JeremyP
Back in the days of OS X 10.4 I spent some time failing to write a VFS for OS X. In those days, of the major subsystems of the kernel, only the network stack and the VFS were still truly BSD. At that time, even the VFS had been partly rewritten to make it more modular (all the BSD VFS data structures became opaque pointers and the API was through what were called KPI functions). I believe the network stack was going the same way. There was also a thin layer at the interface with userland that made the OS look like BSD to userland programs.
回到 OS X 10.4 的时代,我花了一些时间未能为 OS X 编写 VFS。那时,在内核的主要子系统中,只有网络堆栈和 VFS 仍然是真正的 BSD。当时,甚至 VFS 也被部分重写以使其更加模块化(所有 BSD VFS 数据结构都变成了不透明的指针,并且 API 是通过所谓的 KPI 函数实现的)。我相信网络堆栈也在以同样的方式发展。在与用户空间的接口处还有一个薄层,使操作系统对于用户空间程序看起来像 BSD。
Everything else had been pretty much rewritten or replaced: memory management, process management etc came from the Mach microkernel; the device driver subsystem was written from the ground up by Apple.
其他一切都几乎被重写或替换:内存管理、进程管理等来自 Mach 微内核;设备驱动子系统是由 Apple 从头开始编写的。
In terms of userland programming, OS X is very similar to BSD and programs written for BSD should be easily portable. However, OS X has a lot of APIs that aren't available in BSD. These include almost everything to do with the user interface - graphics, sound etc. There are also other interfaces that don't exist in BSD such as the launch API which is the OS X preferred way of launching background processes.
在用户态编程方面,OS X 与 BSD 非常相似,为 BSD 编写的程序应该很容易移植。但是,OS X 有很多在 BSD 中不可用的 API。这些几乎包括与用户界面有关的所有内容 - 图形、声音等。还有其他一些 BSD 中不存在的界面,例如启动 API,它是 OS X 启动后台进程的首选方式。
回答by Norman Gray
The Wikipedia BSD articleis good (and accords with my own understanding, for what that's worth). It says that Darwin, the system on which Apple's Mac OS X is built, is a derivative of 4.4BSD-Lite2 and FreeBSD, and notes that 4.4BSD is the last release that Berkeley was involved with.
维基百科BSD 文章很好(并且符合我自己的理解,这是值得的)。它说Darwin 是构建 Apple Mac OS X 的系统,是 4.4BSD-Lite2 和 FreeBSD 的衍生版本,并指出 4.4BSD 是 Berkeley 参与的最后一个版本。
So, Darwin is as BSD as you can get (just like all the other BSDs!). OS X refers to those parts of the distribution which aren't open-source, principally the GUI, but including a variety of frameworks, and anything which relies on these won't be portable.
所以,Darwin 是你所能得到的 BSD(就像所有其他 BSD 一样!)。OS X 指的是发行版中那些不是开源的部分,主要是 GUI,但包括各种框架,任何依赖于这些框架的东西都将不可移植。
OS X as a whole is a UNIX 03system. That's equivalent to being a truly POSIX-compliant system (as opposed to being POSIX-like).
OS X 整体上是一个UNIX 03系统。这相当于是一个真正符合 POSIX 的系统(而不是类似于 POSIX)。
As other answers have noted, the userland parts of the OS are unsurprising to anyone with much unix experience, and I've rarely had any difficulty building portable-unix software on OS X.
正如其他答案所指出的那样,对于具有丰富 Unix 经验的任何人来说,操作系统的用户区部分都不足为奇,而且我在 OS X 上构建可移植的 Unix 软件很少遇到任何困难。
In contrast, the non-userland parts of the OS are pretty different. Apple seems to be willing to innovate in those areas fairly cheerfully. I think (but I'm not positive) that these changes are formally part of Darwin. One of the most obvious differences is that launchdhas replaced cron, at, inetd, and much of the startup infrastructure.
相比之下,操作系统的非用户区部分则大不相同。苹果似乎很乐意在这些领域进行创新。我认为(但我并不肯定)这些变化是达尔文的正式组成部分。最明显的区别之一是launchd已经取代了 cron、at、inetd 和大部分启动基础设施。
回答by Borealid
If the Mac software uses Cocoa, Apple's proprietary display library (which it does, if it runs on the Mac with a GUI and does not require starting an X server), then you may have some issues running the code on a normal BSD system.
如果 Mac 软件使用 Cocoa,Apple 的专有显示库(它确实如此,如果它在带有 GUI 的 Mac 上运行并且不需要启动 X 服务器),那么在普通 BSD 系统上运行代码可能会遇到一些问题。
If your code only uses POSIX-specified functions, it will cleanly port to Linux, BSD, and even Windows.
如果您的代码只使用 POSIX 指定的函数,它将干净地移植到 Linux、BSD 甚至 Windows。
It is true that Mac OS X and BSD are related. Although they have different kernels, they share a common ancestor and significant userland code. Obviously, I can't quantify "how close" - that's subjective.
Mac OS X 和 BSD 确实是相关的。尽管它们具有不同的内核,但它们共享一个共同的祖先和重要的用户空间代码。显然,我无法量化“有多接近”——这是主观的。
回答by Christopher Creutzig
Mac OS X isone flavor of BSD Unix. As Borelaid already pointed out, that does not necessarily mean that porting Mac apps to other flavors of BSD would be easy or even manageable, much less so than between other common BSD flavors. Every one of them brings their own specifics, and OS X more than most.
Mac OS X是BSD Unix 的一种。正如 Borelaid 已经指出的那样,这并不一定意味着将 Mac 应用程序移植到其他 BSD 版本会很容易,甚至易于管理,远不如其他常见 BSD 版本之间那么容易。他们每个人都有自己的细节,而 OS X 比大多数人都多。
Porting programs from otherBSD flavors to OS X also involves work and does not always work (smoothly or at all), but is usually much more straightforward.
将程序从其他BSD 风格移植到 OS X 也涉及工作,并不总是工作(顺利或根本),但通常更直接。
回答by Philipp
It depends on what kinds of apps you are trying to port. If you write POSIX-compatible C/C++ console programs, they will compile and work just fine under any POSIX-compatible system (mostly Linux and BSD flavors), but note that OS X often doesn't implement the newest POSIX functions (e.g. utimensat
) which are available in Linux. On the other hand, graphical applications use Cocoa or the older Carbon, which would require GNUstep. Porting graphical applications is quite uncommon because every graphical environment has different design standards and conventions, so graphical applications usually have to be written from scratch for each graphical environment.
这取决于您尝试移植的应用程序类型。如果您编写兼容 POSIX 的 C/C++ 控制台程序,它们将在任何兼容 POSIX 的系统(主要是 Linux 和 BSD 风格)下编译和工作得很好,但请注意,OS X 通常不实现最新的 POSIX 功能(例如utimensat
)这些在 Linux 中可用。另一方面,图形应用程序使用 Cocoa 或较旧的 Carbon,这需要 GNUstep。移植图形应用程序并不常见,因为每个图形环境都有不同的设计标准和约定,因此通常必须为每个图形环境从头开始编写图形应用程序。
回答by JulesLt
Installed - no.
安装 - 没有。
Ported from source, maybe - see Gnustep, Cocotron, EtoileOS - all of which offer varying degrees of compatibility with the Cocoa development stack (but not with the older Carbon). There is a limited amount of x-platform objective-C software developed that way.
从源代码移植,也许 - 请参阅 Gnustep、Cocotron、EtoileOS - 所有这些都提供了与 Cocoa 开发堆栈(但不与较旧的 Carbon)不同程度的兼容性。以这种方式开发的 x 平台 Objective-C 软件数量有限。