1. 操作系统的服务 Operating System Services
Operating systems provide an environment for execution of programs and services to programs and users One set of operating-system services provides functions that are helpful to the user:
- User interface - Almost all operating systems have a user interface (UI).
- Varies between Command-Line (CLI), Graphics User Interface (GUI), Batch
- Program execution - The system must be able to load a program into memory and to run that program, end execution,either normally or abnormally (indicating error)
-
I/O operations - A running program may require I/O, which may involve a file or an I/O device
- File-system manipulation - The file system is of particular interest. Programs need to read and write files and directories, create and delete them, search them, list file Information, permission management.
- Communications – Processes may exchange information, on the same computer or between computers over a network
- Communications may be via shared memory or through message passing (packets moved by the OS)
- Error detection – OS needs to be constantly aware of possible errors
- May occur in the CPU and memory hardware, in I/O devices, in user program
- For each type of error, OS should take the appropriate action to ensure correct and consistent computing
- Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system
Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing
- Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them
- Many types of resources - CPU cycles, main memory, file storage, I/O devices.
- Accounting - To keep track of which users use how much and what kinds of computer resources
- Protection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other
- Protection involves ensuring that all access to system resources is controlled
- Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts
操作系统为程序和用户提供程序和服务执行提供环境 一组操作系统服务提供对用户有帮助的功能:
- 用户界面 - 几乎所有操作系统都有用户界面 (User Interface, UI)。
- 在命令行 (CLI)、图形用户界面 (GUI)、批处理之间有所不同
- 程序执行 - 系统必须能够将程序加载到内存中并运行该程序,结束执行,正常或异常(指示错误)
-
I/O 操作 - 正在运行的程序可能需要 I/O,这可能涉及文件或 I/O 设备
- 文件系统操作 - 文件系统特别重要。程序需要读写文件和目录,创建和删除它们,搜索它们,列出文件信息,权限管理。
- 通信 – 进程可以在同一台计算机上或通过网络在计算机之间交换信息
- 通信可以通过共享内存或消息传递(操作系统移动的数据包)
- 错误检测 – 操作系统需要不断意识到可能的错误
- 可能发生在 CPU 和内存硬件、I/O 设备、用户程序中
- 对于每种类型的错误,操作系统应采取适当的措施,以确保正确和一致的计算
- 调试设施可以大大提高用户和程序员高效使用系统的能力
存在另一组操作系统功能,用于通过资源共享确保系统本身的有效运行(不是为了帮助用户,而是为了保证系统本身高效运行)
- 资源分配 - 当多个用户或多个作业同时运行时,必须为每个用户或作业分配资源
- 多种类型的资源 - CPU周期,主内存,文件存储,I/O设备。
- 记账- 跟踪哪些用户使用多少以及哪种计算机资源
- 保护和安全 - 存储在多用户或联网计算机系统中的信息的所有者可能希望控制该信息的使用,并发进程不应相互干扰
- 保护涉及确保对系统资源的所有访问都受到控制
- 系统的安全性需要用户身份验证,扩展到保护外部I / O设备免受无效访问尝试
2. 用户与操作系统的界面 User Operating System Interface
用户与操作系统的界面有多种方式。这里,讨论两种基本方案。
-
一种提供命令行界面或命令解释程序(command interpreter,CLI),允许用户直接输入命令,以供操作系统执行。
-
另一种允许用户通过图形用户界面(GUI)与操作系统交互。
2.1 命令解释程序 CLI
命令解释程序的主要功能是,获取并执行用户指定的下一条命令。这层提供了许多命令来操作文件:创建、删除、列出、打印、复制、执行等。MS-DOS 和UNIX 的外壳就是这么工作的。这些命令的实现有两种常用方法。 一种方法是,命令解释程序本身包含代码以执行这些命令。例如,删除文件的命令可让命令解释程序跳转到相应的代码段,以设置参数并执行相应系统调用。对于这种方法,所能提供命令的数量决定命令解释程序的大小,因为每个命令都要有实现代码。 另一种方法是,通过系统程序实现大多数的命令,常用于许多操作系统,如 UNIX。这命令解释程序不必理解命令,而只要通过命令确定一个文件,以加载到内存并执行。
(以上在书2.2.1 P40)
CLI or command interpreter allows direct command entry
- Sometimes implemented in kernel, sometimes by systems program
- Sometimes multiple flavors implemented – shells
- Primarily fetches a command from user and executes it
- Sometimes commands built-in, sometimes just names of programs
- If the latter, adding new features doesn’t require shell modification
CLI 或命令解释器允许直接输入命令
- 有时在内核中实现,有时由系统程序实现
- 对于具有多个可选命令解释程序的系统,解释程序称为外壳(shell)
- 主要从用户获取命令并执行
- 有时命令内置,有时只是程序名称
- 如果是后者,添加新功能不需要修改外壳
## 2.2 图形用户界面 GUI
User-friendly desktop metaphor interface
- Usually mouse, keyboard, and monitor
- Icons represent files, programs, actions, etc
- Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function,open directory (known as a folder)
- Invented at Xerox PARC
Many systems now include both CLI and GUI interfaces
- Microsoft Windows is GUI with CLI “command” shell
- Apple Mac OS X is “Aqua” GUI interface with UNIX kernel underneath and shells available
- Unix and Linux have CLI with optional GUI interfaces (CDE, KDE, GNOME)
用户友好的桌面隐喻界面
- 通常是鼠标、键盘和显示器
- 图标代表文件,程序,动作等
- 界面中对象上的各种鼠标按钮会导致各种操作(提供信息,选项,执行功能,打开目录(称为文件夹)
- 施乐PARC发明
许多系统现在同时包含 CLI 和 GUI 界面
- Microsoft Windows是带有CLI“命令”外壳的GUI
- Apple Mac OS X是“Aqua”GUI界面,下面有UNIX内核和shell可用
- Unix和Linux具有带有可选GUI界面(CDE,KDE,GNOME)的CLI。
Touchscreen Interfaces
Touchscreen devices require new interfaces
- Mouse not possible or not desired
- Actions and selection based on gestures
- Virtual keyboard for text entry
Voice commands.
触摸屏界面
触摸屏设备需要新的接口
- 鼠标不可能或不需要
- 基于手势的操作和选择
- 用于文本输入的虚拟键盘
语音命令。
3. 系统调用 System Calls
- Programming interface to the services provided by the OS
- Typically written in a high-level language (C or C++)
- Mostly accessed by programs via a high-level Application Programming Interface (API) rather than direct system call use
- Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM)
Note that the system-call names used throughout this text are generic
- 操作系统提供的服务的编程接口
- 通常用高级语言(C 或 C++)编写
- 主要由程序通过高级应用程序编程接口 (API) 访问,而不是直接使用系统调用
- 三种最常见的API是Win32 API for Windows,POSIX API用于基于POSIX的系统(包括几乎所有版本的UNIX,Linux和Mac OS X)和Java API for the Java Virtual machine(JVM)
请注意,本文中使用的系统调用名称是通用的
一上图中所有操作可以封装成一个API
3.1 System Call Implementation
- Typically, a number associated with each system call
- System-call interface maintains a table indexed according to these numbers
- The system call interface invokes the intended system call in OS kernel and returns status of the system call and any return values
- The caller need know nothing about how the system call is implemented
- Just needs to obey API and understand what OS will do as a result call
- Most details of OS interface hidden from programmer by API
- Managed by run-time support library (set of functions built into libraries included with compiler)
- 通常,与每个系统调用关联的数字
- 系统调用接口维护一个根据这些数字编制索引的表
- 系统调用接口在操作系统内核中调用预期的系统调用,并返回系统调用的状态和任何返回值
- 调用方不需要知道系统调用是如何实现的
- 只需要遵守 API 并了解操作系统将作为结果调用做什么
- 通过API对程序员隐藏的操作系统接口的大部分细节
- 由运行时支持库管理(编译器附带的库中内置的函数集)
3.2 System Call Parameter Passing
- Often, more information is required than simply identity of desired system call
- Exact type and amount of information vary according to OS and call
- Three general methods used to pass parameters to the OS
- Simplest: pass the parameters in registers
- In some cases, may be more parameters than registers
- Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register
- This approach taken by Linux and Solaris
- Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system
- Block and stack methods do not limit the number or length of parameters being passed
- Simplest: pass the parameters in registers
- 通常,需要更多信息,而不仅仅是所需系统调用的标识
- 确切的信息类型和数量因操作系统和调用而异
- 用于将参数传递给操作系统的三种通用方法
- 最简单的:在寄存器中传递参数
- 在某些情况下,可能比寄存器更多的参数
- 存储在内存中的块或表中的参数,而块或表的地址通过寄存器来传递
- Linux和Solaris采用的这种方法
- 由程序放置或推送到堆栈上的参数,并由操作系统从堆栈中弹出
- 块和堆栈方法不限制传递的参数的数量或长度
- 最简单的:在寄存器中传递参数
4. 系统调用的类型 Types of System Calls
系统调用大概可以分为六类:
Process control
- create process, terminate process
- end, abort
- load, execute
- get process attributes, set process attributes
- wait for time
- wait event, signal event
- allocate and free memory
- Dump memory if error
- Debugger for determining bugs, single step execution
- Locks for managing access to shared data between processes
File management
- create file, delete file
- open, close file
- read, write, reposition
- get and set file attributes
Device management
- request device, release device
- read, write, reposition
- get device attributes, set device attributes
- logically attach or detach devices
Information maintenance
- get time or date, set time or date
- get system data, set system data
- get and set process, file, or device attributes
Communications
- create, delete communication connection
- send, receive messages if message passing model to host name or process name
- From client to server
- Shared-memory model create and gain access to memory regions
- transfer status information
- attach and detach remote devices
Protection
- Control access to resources
- Get and set permissions
- Allow and deny user access
进程控制
- 创建进程,终止进程
- 结束,中止
- 加载,执行
- 获取进程属性,设置进程属性
- 等待时间
- 等待事件,信号事件
- 分配和释放内存
- 如果出错转储内存
- 用于确定错误的调试器,单步执行
- 用于管理对进程间共享数据的访问的锁
文件管理
- 创建文件,删除文件
- 打开、关闭文件
- 读、写、重新定位
- 获取和设置文件属性
设备管理
- 请求设备,释放设备
- 读、写、重新定位
- 获取设备属性,设置设备属性
- 逻辑上附加或分离设备
信息维护
- 获取时间或日期,设置时间或日期
- 获取系统数据,设置系统数据
- 获取和设置进程、文件或设备属性
通信
- 创建、删除通讯连接
- 如果消息传递模型为主机名或进程名,则发送、接收消息
- 从客户端到服务器
- 共享内存模型创建和访问内存区域
- 传输状态信息
- 连接和分离远程设备
保护
- 控制对资源的访问
- 获取和设置权限
- 允许和拒绝用户访问
进程控制
单任务例子
MS-DOS 操作系统是个单任务的系统,在计算机启动时它就运行一个命令解释程序(图2-9a)。由于MS-DOS 是单任务的,它采用了一种简单方法来执行程序而且不创建新进程。它加载程序到内存,并对自身进行改写,以便为新程序提供尽可能多的空间(图2-9)。接着,它将指令指针设为程序的第一条指令。然后,运行程序,或者错误引起中断,或者程序执行系统调用来终止。无论如何,错误代码会保存在系统内存中以便以后使用。之后,命令解释程序中的尚未改写部分重新开始执行。它首先从磁盘中重新加载命令解释程序的其他部分。然后,命令解释程序会向用户或下个程序提供先前的错误代码。
多任务例子
FreeBSD(源于 Berkeley UNIX)是个多任务系统。在用户登录到系统后,用户所选的外壳就开始运行。这种外壳类似于MS-DOS外壳:按用户要求,接受命令并执行程序。不过,由于FreeBSD 是多任务系统,命令解释程序在另一个程序执行,也可继续执行(图2-10)。为了启动新进程,外壳执行系统调用fork()。接着,所选程序通过系统调用exec()加载到内存,程序开始执行。根据命令执行方式,外壳要么等待进程完成,要么后台执行进程。对于后一种情况,外壳可以马上接受下个命令。当进程在后台运行时,它不能直接接受键盘输人,这是因为外壳已在使用键盘。因此I/0可通过文件或GUI来完成。同时,用户可以让外壳执行其他程序,监视运行进程状态,改变程序优先级等。当进程完成时,它执行系统调用exit()以终止并将0或非0的错误代码返回到调用进程。这一状态(或错误)代码可用于外壳或其他程序。第3 章将通过一个使用系统调用 fork()和exec()的程序例子来讨论进程。
5. 系统程序 System Programs
System programs provide a convenient environment for program development and execution. They can be divided into:
- File manipulation
- Status information sometimes stored in a File modification
- Programming language support
- Program loading and execution
- Communications
- Background services
- Application programs
Most users’ view of the operation system is defined by system programs, not the actual system calls
Provide a convenient environment for program development and execution.Some of them are simply user interfaces to system calls; others are considerably more complex
- File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories
- Status information
- Some ask the system for info - date, time, amount of available memory, disk space, number of users
- Others provide detailed performance, logging, and debugging information
- Typically, these programs format and print the output to the terminal or other output devices
- Some systems implement a registry - used to store and retrieve configuration information
- File modification
- Text editors to create and modify files
- Special commands to search contents of files or perform transformations of the text
- Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes provided
- Program loading and execution- Absolute loaders,relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language
- Communications - Provide the mechanism for creating virtual connections among processes, users, and computer systems
- Allow users to send messages to one another’s screens, browse web pages, send electronic-mail messages, log in remotely, transfer files from one machine to another
- Background Services
- Launch at boot time Some for system startup, then terminate Some from system boot to shutdown
- Provide facilities like disk checking, process scheduling, error logging, printing
- Run in user context not kernel context
- Known as services, subsystems, daemons
- Application programs
- Don’t pertain to system
- Run by users
- Not typically considered part of OS
- Launched by command line, mouse click, finger poke
系统程序为程序开发和执行提供了方便的环境。它们可以分为:
- 文件操作
- 有时存储在文件修改中的状态信息
- 编程语言支持
- 程序加载和执行
- 通讯
- 后台服务
- 应用程序
大多数用户对操作系统的看法是由系统程序定义的,而不是实际的系统调用
为程序开发和执行提供便利的环境,其中一些只是系统调用的用户界面;其他的要复杂得多
- 列出以及一般操作文件和目录
- 状态信息
- 有些人向系统询问信息 - 日期、时间、可用内存量、磁盘空间、用户数量
- 其他提供详细的性能、日志记录和调试信息
- 通常,这些程序将输出格式化并打印到终端或其他输出设备
- 一些系统实现了一个注册表 - 用于存储和检索配置信息
- 文件修改
- 用于创建和修改文件的文本编辑器
- 搜索文件内容或执行文本转换的特殊命令
- 程序语言支持 - 有时提供编译器、汇编器、调试器和解释器
- 程序加载和执行 - 绝对加载器、可重定位加载器、链接编辑器和覆盖加载器、更高级别和机器语言的调试系统
- 通信——提供在进程、用户和计算机系统之间创建虚拟连接的机制
- 允许用户向彼此的屏幕发送消息、浏览网页、发送电子邮件消息、远程登录、将文件从一台机器传输到另一台机器
- 后台服务
- 在启动时启动
- 一些用于系统启动,然后终止
- 一些从系统开机到关机
- 提供磁盘检查、进程调度、错误记录、打印等功能
- 在用户上下文而不是内核上下文中运行
- 一直运行的系统进程称为服务、子系统、守护进程
- 应用程序
- 与系统无关
- 由用户运行
- 通常不被视为操作系统的一部分
- 通过命令行启动,鼠标点击,手指戳
6. 操作系统的设计与实现 Operating System Design and Implementation
6.1 设计目标
- Design and Implementation of OS not “ solvable ” , but some approaches have proven successful
- Internal structure of different Operating Systems can vary widely
- Start the design by defining goals and specifications
- Affected by choice of hardware, type of system
- User goals and System goals
- User goals – operating system should be convenient to use,easy to learn, reliable, safe, and fast
- System goals – operating system should be easy to design,implement, and maintain, as well as flexible, reliable, error-free,and efficient
- 操作系统的设计和实现不是“可解决的”,但一些方法已被证明是成功的
- 不同操作系统的内部结构可能差异很大
- 通过定义目标和规范开始设计
- 受硬件选择、系统类型的影响
- 用户目标和系统目标
- 用户目标 – 操作系统应易于使用、易于学习、可靠、安全、快速
- 系统目标 – 操作系统应易于设计、实施和维护,以及灵活、可靠、无差错和高效
6.2 Important principle to separate policy and mechanism
Policy: What will be done? Mechanism: How to do it?
Mechanisms determine how to do something, policies decide what will be done
The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later (example – timer)
Specifying and designing an OS is highly creative task of software engineerin
策略:将做什么?(如何实现这种功能) 机制:怎么做?(要提供何种功能)
机制决定如何做某事,策略决定做什么
策略与机制的分离是一个非常重要的原则,如果以后要改变策略决策,它允许最大的灵活性(示例 – 计时器)
指定和设计操作系统是软件工程师极具创造性的任务
==提供机制而不是策略,机制是一种框架,而策略是基于框架的具体实现==
6.3 Implementation
Much variation
- Early OSes in assembly language
- Then system programming languages like Algol, PL/1
- Now C, C++
Actually usually a mix of languages
- Lowest levels in assembly
- Main body in C
- Systems programs in C, C++, scripting languages like PERL, Python, shell scripts
More high-level language easier to port to other hardware
- But slower
Emulation can allow an OS to run on non-native hardware
变化很大
- 汇编语言的早期操作系统
- 然后是系统编程语言,如Algol,PL / 1
- 现在的C,C++
实际上通常是多种语言的混合
- 最底层仍用汇编语言
- 主体用C语言
- C,C++,脚本语言如PERL,Python,shell脚本的系统程序
更高级的语言更容易移植到其他硬件
- 但速度较慢
仿真可以允许操作系统在非本机硬件上运行 (让OS可以运行在非本地硬件上(虚拟机))
(Java特点:一次编译,处处运行,缺点是比较慢,C/C++没有这种跨平台的优点)
7. 操作系统的结构 Operating System Structure
General-purpose OS is very large program Various ways to structure ones
- Simple structure – MS-DOS
- More complex – UNIX
- Layered – an abstrcation
- Microkernel -Mach
7.1 Simple Structure – MS-DOS
MS-DOS系统并没有很好地区分功能的接口和层次。例如,应用程序能够访问基本的I/O程序,并直接写到显示器和磁盘驱动。这种自由使MS-DOS易受错误(或恶意)程序的伤害,因此用户程序出错会导致整个系统崩溃。当然,MS-DOS 还受限于当时的硬件。所用的ntel 8088 未能提供双模式和硬件保护因此MS-DOS设计人员除了允许访问基础硬件外,没有其他选择。
MS-DOS – written to provide the most functionality in the least space
- Not divided into modules
- Although MS-DOS has some structure, its interfaces and levels of functionality are not well separated
MS-DOS – 编写用于在最小的空间内提供最多的功能
- 不划分模块
- 虽然MS-DOS有一些结构,但其接口和功能级别并没有很好地分开
7.2 Non Simple Structure – UNIX
另一个例子,即最初的UNIX操作系统,采用有限结构。与MS-DOS一样,UNIX开始也受限于硬件功能。它由两个独立部分组成:内核和系统程序。内核又分为一系列接口和驱动程序,随着UNIX的发展,这些也不断地得以增加和扩展。传统的UNIX 操作系统可以按一定程度的分层来看待,如图 2-12 所示。系统调用接口之下和物理硬件之上的所有部分为内核。内核通过系统调用,可提供文件系统、CPU调度、内存管理和其他操作系统功能总的来说,这一层里面包含了大量功能。这种单片结构使得 UNIX 难以实现与设计。不过它有一个独特的性能优势:系统调用接口和内核通信的开销非常小。因此,UNIX、Linux和Windows 操作系统仍然采用这种简单的单片结构。
Beyond simple but not fully layered
超越简单但不完全分层
UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The UNIX OS consists of two separable parts 1.Systems programs 2.The kernel
- Consists of everything below the system-call interface and above the physical hardware
- Provides the file system, CPU scheduling,memory management, and other operatingsystem functions; a large number of functions for one level
UNIX – 受硬件功能的限制,最初的 UNIX 操作系统结构有限。UNIX 操作系统由两个可分离的部分组成 1.系统程序 2.内核
- 由系统调用接口下方和物理硬件上方的所有内容组成
- 提供文件系统、CPU调度、内存管理等操作系统功能;一个级别的大量功能
7.3 分层方法 Layered Approach
系统模块化的方法有很多,一种是分层法
这里介绍理想中的层次化
The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface.
With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers
操作系统分为多个层(级别),每个层都构建在较低层之上。底层(第 0 层)是硬件;最高的(N层)是用户界面。
通过模块化,选择层,使得每个层仅使用较低层的功能(操作)和服务
分层法的主要优点在于简化了构造和调试。所选的层次要求每层只能调用更低层的功能(操作)和服务。这种方法简化了系统的调试和验证。系统的设计和实现得以简化。
分层法的主要难点在于合理定义各层。由于每层只能利用更低层的功能,因此有必要仔细规划。例如,用于备份存储(虚拟内存算法所用的磁盘空间)的设备驱动程序应位于内存管理程序之下,这是因为内存管理需要用到这些功能来备份存储。
分层实现的最后一个问题是与其他方法相比效率稍差。例如,当一个用户程序执行 I/O 操作时,它执行系统调用并陷人IO层,I/O 层会调用内存管理层,内存管理层接着调用CPU调度层最后传递到硬件。在每一层,参数可能会被修改,数据可能需要传递,等等。每层都为系统调用增加额外开销。最终结果是,与非分层的系统相比,这样的系统调用需要执行更长时间。
7.4 微内核 Microkernel System Structure
- Moves as much from the kernel into user space
- Mach example of microkernel
- Mac OS X kernel (Darwin) partly based on Mach
- Communication takes place between user modules using message passing
- Benefits:
- Easier to extend a microkernel
- Easier to port the operating system to new architectures
- More reliable (less code is running in kernel mode)
- More secure
- Detriments:
- Performance overhead of user space to kernel space communication
- 尽可能多地从内核移动到用户空间(只在内核中留下必须的功能,其他可有可无的功能放到用户空间,使得内核变小)
- 微内核的Mach 例子
- Mac OS X内核(达尔文)部分基于Mach
- 使用消息传递在用户模块之间进行通信
- 好处:
- 更容易扩展微内核
- 更容易将操作系统移植到新的架构
- 更可靠(在内核模式下运行的代码更少,所以更稳定)
- 更安全
- 危害:
- 用户空间到内核空间通信的性能开销 (之前都在内核模式下就可以完成的任务,由于微内核中将一些功能放到了用户空间,所以会导致内核态和用户态的大量沟通切换)
(鸿蒙系统就是)
7.5 模块 Modules
Many modern operating systems implement loadable kernel modules
- Uses object-oriented approach
- Each core component is separate
- Each talks to the others over known interfaces
- Each is loadable as needed within the kernel
Overall, similar to layers but with more flexible
- Linux, Solaris, etc
许多现代操作系统实现了可加载的内核模块
- 使用面向对象的方法
- 每个核心组件都是独立的
- 每个都通过已知接口与其他接口通信
- 每个都可以根据需要在内核中加载
总体而言,类似于图层,但更灵活
- Linux,Solaris等
7.6 混合系统 Hybrid Systems
同时用分层和微内核
Most modern operating systems are actually not one pure model
- Hybrid combines multiple approaches to address performance, security, usability needs
- Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic loading of functionality
- Windows mostly monolithic, plus microkernel for different subsystem personalities
Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment
- Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions)
大多数现代操作系统实际上不是一个纯粹的模型
- 混合结合了多种方法来解决性能、安全性和可用性需求
- 内核地址空间中的 Linux 和 Solaris 内核,因此是单片式的,加上用于动态加载功能的模块化
- Windows主要是单片的,加上不同子系统个性的微内核
Apple Mac OS X 混合、分层、Aqua UI 和 Cocoa 编程环境
- 下面是由Mach微内核和BSD Unix部分组成的内核,以及I / O套件和可动态加载模块(称为内核扩展)
7.6.1 IOS
Apple mobile OS for iPhone, iPad
- Structured on Mac OS X, added functionality
- Does not run OS X applications natively
- Also runs on different CPU architecture (ARM vs. Intel)
- Cocoa Touch Objective-C API for developing apps
- Media services layer for graphics, audio, video
- Core services provides cloud computing,databases
- Core operating system, based on Mac OS X kernel
苹果手机操作系统适用于iPhone,iPad
- 在Mac OS X上结构化,增加了功能
- 无法在本地运行 OS X 应用程序
- 也运行在不同的CPU架构上(ARM与英特尔)
- Cocoa Touch Objective-C API 用于开发应用程序
- 图形、音频、视频的媒体服务层
- 核心服务提供云计算,数据库
- 核心操作系统,基于Mac OS X内核
7.6.2 Android
- Developed by Open Handset Alliance (mostly Google)
- Open Source
- Similar stack to IOS
- Based on Linux kernel but modified
- Provides process, memory, device-driver management
- Adds power management
- Runtime environment includes core set of libraries and Dalvik virtual machine
- Apps developed in Java plus Android API
- Java class files compiled to Java bytecode then translated to executable than runs in Dalvik VM
- Apps developed in Java plus Android API
- Libraries include frameworks for web browser (webkit), database (SQLite), multimedia, smaller libc
(应用程序必须在Dalvik虚拟机中运行)
- 由开放手机联盟(主要是谷歌)开发
- 开源
- 与IOS类似的堆栈
- 基于Linux内核,但已修改
- 提供进程、内存、设备驱动程序管理
- 添加电源管理
- 运行时环境包括核心库集和 Dalvik 虚拟机
- 用Java和Android API开发的应用程序
- Java类文件编译成Java字节码,然后转换为可执行文件,而不是在Dalvik VM中运行
- 用Java和Android API开发的应用程序
- 库包括Web浏览器(webkit),数据库的框架 (SQLite), 多媒体, 较小的 libc
8. 操作系统的调试 Operating-System Debugging
- Debugging is finding and fixing errors, or bugs
- OS generate log files containing error information
- Failure of an application can generate core dump file capturing memory of the process
- Operating system failure can generate crash dump file containing kernel memory
- Beyond crashes, performance tuning can optimize system performance
- Sometimes using trace listings of activities, recorded for analysis
- Profiling is periodic sampling of instruction pointer to look for statistical trends
-
Kernighan’s Law: “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
- 调试是发现并修复错误或缺陷
- 操作系统生成包含错误信息的日志文件
- 应用程序失败可以生成核心转储文件捕获进程的内存
- 操作系统故障可以生成包含内核内存的故障转储文件
- 除了崩溃,性能调整可以优化系统性能
- 有时使用跟踪活动列表,记录以供分析
- 分析是指令指针的定期采样以寻找统计趋势
- Kernighan 定律:“调试的难度是编写代码的两倍。因此,如果你尽可能聪明地编写代码,那么根据定义,你还不够聪明,无法调试它。”
8.1 性能优化 Performance Tuning
- Improve performance by removing bottlenecks
- OS must provide means of computing and displaying measures of system behavior
-
For example, “top” program or Windows Task Manager
- 通过消除瓶颈来提高性能
- 操作系统必须提供计算和显示系统行为度量的方法
- 例如,“顶级”程序或Windows任务管理器
8.2 DTrace
9. 操作系统的生成 Operating System Generation
- Operating systems are designed to run on any of a class of machines; the system must be configured for each specific computer site
- SYSGEN program obtains information concerning the specific configuration of the hardware system
- Used to build system-specific compiled kernel or systemtuned
- Can general more efficient code than one general kernel
- 操作系统设计为在任何一类机器上运行;必须为每个特定的计算机站点配置系统。
- SYSGEN程序获取有关硬件系统特定配置的信息
- 用于构建系统特定的编译内核或系统调优
- 可以比一个通用内核更高效的代码
10. 系统引导 System Boot
- When power initialized on system, execution starts at a fixed memory location
- Firmware ROM used to hold initial boot code
- Operating system must be made available to hardware so hardware can start it
- Small piece of code – bootstrap loader, stored in ROM or EEPROM locates the kernel, loads it into memory, and starts it
- Sometimes two-step process where boot block at fixed location loaded by ROM code, which loads bootstrap loader from disk
- Common bootstrap loader, GRUB, allows selection of kernel from multiple disks, versions, kernel options
-
Kernel loads and system is then running
- 当系统上的电源初始化时,在固定内存位置开始执行
- 用于保存初始启动代码的固件 ROM
- 操作系统必须可供硬件使用,以便硬件可以启动它
- 一小段代码 – 存储在ROM或EEPROM中的引导加载器定位内核,将其加载到内存中并启动它
- 有时是两步过程,其中固定位置的引导块由ROM代码加载,从磁盘加载引导加载程序
- 通用引导加载程序,GRUB,允许从多个磁盘、版本、内核选项中选择内核
- 内核加载,系统然后运行