mac 和 linux内核简单比较

来源:互联网 发布:java 读取文件内容 编辑:程序博客网 时间:2024/06/05 19:16
macOS内核源码官方链接
https://opensource.apple.com/

内核概述(我觉得有意思的部分)
OS X:完整操作系统
内核:Darwin 包含 XNU (混合式内核,包含1. Mach微内核,2. BSD层建立在Mach之上,3. I/O kit). 有趣的是,XNU's Not Unix.
XNU给用户态主要提供BSD的接口,不仅有POSIX兼容的系统调用,也有BSD独有的调用。同时也提供少量Mach接口(竟然称之为API)
由于纯微内核只有学术价值,因此OS X使用的是混合内核。
XNU不是BSD的完整实现,比如BSD的brk()是缺失的;XNU的kext和BSD的kmod不兼容。
没有像Linux那样用户可见的文件系统procfs,但还是可以使用sysctl命令
I/O kit是C++实现的,但只用到C++的严格子集

开机流程,自行对比Linux
The kernel first initializes all the data structures needed to support Mach and BSD. Next, the kernel initializes the I/O Kit, which connects the kernel with the set of extensions that correspond to the machine’s hardware configuration. The kernel then finds and mounts the root filesystem. Finally, it launches the first process on the system, launchd, which is responsible for bootstrapping the system as well as launching daemons on behalf of the system or users.
(摘自《Mac OS X for UNIX Geek》一书)

和Linux软硬件对比的个人总结
EFI对应BIOS
NVRAM对应CMOS
boot.efi对应grub
launched对应init
kext对应ko

对比宏内核和微内核的架构
宏内核:

微内核:

(图片来源:《Mac OS X for UNIX Geek》)