Ch2 Operating-System Structures
Ch2 Operating-System Structures
Structures
Chapter 2: Operating-System Structures
Operating System Services
User Operating System Interface
System Calls
Types of System Calls
System Programs
Operating System Design and Implementation
Operating System Structure
Virtual Machines
Operating System Generation
System Boot
User interface,命令接口- Almost all operating systems have a user interface (UI)
Command-Line Interface (CLI) ,命令行用户接口,文本界面
Graphics User Interface (GUI), 图形用户接口
Touch-Screen Interface,触摸屏接口
Choice of Interface,语音接口
……
Linux、UNIX:bash、sh、tcsh
Voice commands
(Note that the system-call names used throughout this text are generic)
应用编程接口(API)其实是一组函数定义,这些函数说明了如何获得一个给
定的服务;而系统调用是通过软中断向内核发出一个明确的请求,每个系
统调用对应一个封装例程(wrapper routine,唯一目的就是发布系统调
用)。一些API应用了封装例程。
API还包含各种编程接口,如:C库函数、OpenGL编程接口等
系统调用的实现是在内核完成的,而用户态的函数是在函数库中实现的
应用程序 C库 内核
int main(void) {
int result; This is a
result = add_function(a,b); function call.
return 0;
}
time()
Process OS Kernel
int main(void) {
time(NULL); invoking a system call
return 0;
}
Example. The “time()” system call.
time()
Operating
System
User Process Hardware
printf()
No
malloc() Who are they?!
No
fopen() No
fclose() No
If they are not system calls, then they are function calls!
Take fopen() as an example.
fopen() invokes the system call open().
So, why people invented fopen()?
Because open() is too primitive and is not programmer-friendly!
Those functions are usually packed inside an object called the library file.
$ ls /lib/libc*
/lib/libc-2.9.so ......
$ _
A library
Application
containing the OS Kernel
Code fopen() function.
open()
Block and stack methods do not limit the number or length of parameters being passed
Process control
File management
Device management
Information maintenance
Communications
Protection
UNIX环境高级编程(第2版),W.Richard Stevens,尤晋元译,人民邮电出版社
Linux/UNIX系统编程手册(上、下册),Michael Kerrisk著,孙剑等译,人民邮电出版社,
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
Operating system 季江民 29
Types of System Calls (cont.)
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
Operating system 季江民
attach and detach remote devices
31
Types of System Calls (Cont.)
Protection
Control access to resources
Get and set permissions
Allow and deny user access
Win32 CreateProcess
:example\newproc-win32.c
C program invoking printf() library call, which calls write() system call
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
API与ABI不同?
API定义了源代码和库之间的接口,同样的代码可以在支持这个API的任
何系统中编译 ;
ABI允许编译好的二进制代码在使用兼容ABI的系统中无需改动就能运行
。
Design and Implementation of OS not “solvable”, but some approaches have proven successful
Internal structure of different Operating Systems can vary widely
Start 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
操作系统设计有着不同于一般应用系统设计的特征:
复杂程度高
研制周期长
正确性难以保证
Windows 2000开发的艰辛与规模
最早Uinx是1400行代码;
Windows xp有4000万行代码;
fedroa core有2亿多行代码,Linux kernel 5.10有2千多万行代码。
解决途径:
良好的操作系统结构
先进的开发方法和工程化的管理方法(软件工程)
高效的开发工具
功能设计:操作系统应具备哪些功能
算法设计:选择和设计满足系统功能的算法和策略,并分析和估算其效能
结构设计:选择合适的操作系统结构
按照系统的功能和特性要求,选择合适的结构,使用相应的结构设计方法
将系统逐步地分解、抽象和综合,使操作系统结构清晰、简单、可靠、易
读、易修改,而且使用方便,适应性强
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
Simple Structure简单结构
Layered Approach层次化结构
Monolithic Kernels Structure单/宏内核结构
Microkernel 微内核
Modules 模块
Hybrid Systems 混合结构
Monolithic Kernels :the entire code of the kernel — including all its
subsystems such as memory management, filesystems, or device
drivers — is packed into a single file. Each function has access to all
other parts of the kernel;
Earliest and most common OS architecture (UNIX)
Every component of the OS is contained in the Kernel
Examples: OS/360, VMS and Linux
Advantages:
highly efficient because of direct communication between components
Disadvantages:
Difficult to isolate source of bugs and other errors
Hard to modify and maintain
Kernel gets bigger as the OS develops.
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
系统支撑
系统支持进程 服务进程 用户程序 环境子系统
处理器
子系统动态链接库
用户态
用户态
核心态
执行体 核心态
图形引擎
核心 设备驱动程序
硬件抽象层(HAL)
ROM中POST(Power On Self-Test)代码
BIOS/EFI(Extended Firmware Interfacte)
MBR(Main Boot Record)
引导扇区(Boot sector)
NTLDR/WinLoad
NTOSKRNL/HAL/BOOTVID/KDCOM
SMSS.EXE
WinLogon.EXE
Collects data for a specific event, such as steps involved in a system call
invocation
Tools include
strace – trace system calls invoked by a process
ch1 操作系统概述习题分析.pptx
在“学在浙大”中,请按时完成
Chapters 3
of the text book: