2017年9月14日
07:34
写在前面
本笔记仅仅是本人在上课时的一些随手记录,并不完整也不完全正确。
如有错误,请在评论中或直接联系我指正,谢谢!
- services
- structuring
- installed and customized, boot
Operating-system services
User perspective
UI
CLI(Command-line interface)
Batch
GUI(Graphical user interface)
Program execution
Run, load it to the memory, end program
I/O operations
File or I/O device
File-system manipulation
Communications
Between process/ computers
Via shared memory / through message passing
Error detection
Needs to be constantly aware of possible errors
Take appropriate action
Debugging facilities
Resource sharing
Resource allocation
When jobs running concurrently
Special allocation code
General request and release code
Accounting
Keep track of all resources(How much & What kind of)
Protection and security
Control concurrent processes
System calls & API
Concept: System call/ function call
区别
含义
Shell: a set of command
操作系统最外面一层,管理用户与操作系统的交互
等待用户输入,向操作系统解释你的输入,并处理
System calls
Programming interface
Written in high-level language
Application Program Interface(API) rather than direct system call use
Most common API:
Win32
POSIX
JAVA
System call sequence to copy the contents of one file to another file
As an example of a standard API, consider the ReadFile() function in the Win32 API: a function for reading from a file.
The API for this function appears Ln Figure 2.2.
A description of the parameters passed to ReadFile() is as follows:
- HANDLE file—the file to be read.
- LPVOID buffer—a buffer where the data will be read into and written from.
- DWORD bytesToRead—the number of bytes to be read into the buffer.
- LPDWORD bytesRead—the number of bytes read during the last read.
- LPOVERLAPPED ovl—indicates if overlapped I/O is being used.
Each system call have a number
A table indexed according to the number
*Dual mode(See Below)
用户程序不能直接访问系统内核模式提供的服务
系统调用就是一种特殊的接口。通过这个接口,用户可以访问内核空间
系统调用规定用户进程进入内核空间的具体位置
API就是应用程序接口,是一些预定义的函数。跟内核没有必然的联系
两者的区别:
API是函数的定义,规定功能,和内核无直接联系
系统调用通过中断
API需要一个或多个系统调用
API是一个提供给应用程序的接口函数,与程序员进行直接交互
系统调用不与程序员进行交互,根据API函数,通过软中断向内核提交请求
并不是所有API函数一一对应一个系统调用
一个C语言的例子
Design and Implementation of OS
Important principle to separate
Policy(策略): What to do
Mechanism(机制): How to do it
OS Structure
Simple Structure:(DOS)
MS-DOS
Not divided into modules
Most functionality in the least space
Interfaces and levels of functionality are not well separated
Layered Approach:(UNIX)
Problems:
Tend to be less efficient
A layered design was first used in THE operating system. Its six layers are as follows:
Layer 5 | user programs |
Layer 4 | buffering for input and Output |
Layer 3 | operator-console device driver |
Layer 2 | memory management |
Layer 1 | CPU sheduling |
Layer 0 | hardware |
Microkernels:(QNX)
Move as much from the kernel into ‘user’ space
Communication takes place between user modules using message passing
Benefits:
Easier to extend
Easier to port the operating system to new architectures
More reliable (less code is running in kernel mode)
More secure
e.g.: Mac OSX(Mach & BSD -> Kernel) (Hybrid Structure)
Modular:(Solaris)
Kernel: provide core services & certain features to be implemented dynamically
Uses OO
Each core component is separate
Each talks to the others over known interfaces
Each is loadable as needed within the kernel
(Similar to layers but with more flexible)
Problems:
Kernel security crucial
Virtual Machine
Take layered approach to its logical conclusion
Treat hardware and the operating system kernel as though they were all hardware
OS host: simulation, a process has its own processor and (virtual memory)
The resources of the physical computer are shared to create the virtual machines
Ad/Dis
Provides complete protection of system resources
Isolated from all other virtual machines
Permit no direct sharing of resources
Operating-System Generation
*SYSGEN: system generation (部署)(P70)
System Boot
Bootstrap program
Bootstrap loader