前言
本次总结是操作系统的基础知识
操作系统服务
- User interface: CLI(Command-Line),GUI
- Program execution: 加载程序到memory并执行
- I/O operation: 文件或I/O设备
- File-System manipulation: 文件系统管理
- Communications: 进程通信
- Error detection: 异常处理
- Resource allocation: 资源分配,用于多用户
- Accounting: 用于记录各用户分配的资源
- Protection and security
User Operating System Interface
- 操作系统接口包括命令接口(Command Interface)和程序接口(Program Interface,system call)。
- 用户接口(UI),包括CLI和GUI,以及触屏、音控等等
- System Calls(系统调用、程序接口):在进程和内核之间的程序接口
- 应用编程接口(API)其实是一组函数定义,这些函数说明了如何获得一个给 定的服务;而系统调用是通过软中断向内核发出一个明确的请求,每个系 统调用对应一个封装例程(wrapper routine,唯一目的就是发布系统调 用)。一些API应用了封装例程。
- System Call传递参数的方式:传reg,传地址到reg,压栈
- System Call的类型: Process control、 File management、 Device management、information maintenance、Communications
System Service
- File manipulation 创建、删除…
- Status information 时间、硬盘空间、可用内存、日志、debug…
- File modification 文本编辑
- Programming language support 编译器、汇编器、调试器
- Program loading and execution
- Communications 进程、用户、系统
- Application programs
Linkers and Loaders
- relocatable object file: 可以重定位、可以加载到任意物理内存空间
- Linker将obj链接为二进制可运行程序(single binary executable file )
- Application Binary Interface(ABI)
Operating System Structure
- Simple Structure: 简单结构 MS_DOS
- Layered Approach: 层次结构
每一层都是建立在下一层之上,最底层是硬件,最高层是用户接口
- Monolithic Kernels Structure: 单/宏内核结构 OS/360,VMS,Linux,UNIX
- 内核的全部代码包括所有子系统都打包到一个文件中,内核的每一个部分都可以访问内核中所有其他部分。编程时一出现源代码复杂嵌套
- 简单且普遍
- 非常高效,因为各个组件都可以直接通信
- 难以找到bug位置
- 难以修改和维护
- OS的发展使得内核越来越大
- Microkernel: 微内核
- 由”微”内核和若干服务组成,最基本最常用的功能由中央内核实现,其他功能由独立进程实现,并通过明确定义的定义的通信接口与中央内核通信通信
- 动态可扩展性+运行时切换重要组件
- 更加安全和可靠(更少的代码在内核模式下运行)
- 组件间支持复杂通信需要额外的CPU时间
- 用户空间到内核空间的额外开销
- Win NT … Win8 Win 10 Mac OS
- Modules: 模块
- Object-Oriented approach
- core component is separate
- each talks to the others over known interfaces
- each is loadable as needed with more flexible
- Linux Solaris
- Hybrid Systems: 混合结构
- Virtual Machines: 虚拟机
- 采取分层结构,将系统内核和硬件都视为硬件
- 提供与底层裸机相同的接口
- The operating system host creates the illusion that a process has its own processor and (virtual memory)
- Each guest provided with a (virtual) copy of underlying computer
- 通过共享物理机资源来创建虚拟机
- 每个虚拟机都是孤立的且无法直接共享资源