操作系统概念 操作系统结构/Operating-System Structures 第二章笔记

2017年9月14日
07:34

写在前面

本笔记仅仅是本人在上课时的一些随手记录,并不完整也不完全正确。

如有错误,请在评论中或直接联系我指正,谢谢!

原始文件下载:(mht)(pdf)

  1. services
  2. structuring
  3. 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

计算机生成了可选文字: source file destination file Cap fi19 na-rne Write érpgppttp_sqgeén, Acquirepoutputfile Write prömpt\@ screem Acce viripüt Create Outputflle i! filé exis.ts, abort Read ffom'input. file Write'to output,file Until': read CIO\>e output file Write completion message to screen Terminate- nOrmally Figure 2.1 Example of how system calls are used.

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.

return value BOOL ReadFiIe c function name I HANDLE LPVOID LECWORD bytes Read, LPOVERLAPPED ; Figure 2.2 The API fly the ReadFileO function.

open ( ) system call interface open () Implementation Of open l) systern can Figure 2.3 The handling of a user application invoking the open() system call.

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

2.1 The services and functions provided by an operating system can be divided into two main categories. Briefly describe the two categories and discuss how they differ.

22 List five services provided by an operating system that are designed to make it morc convenient fir users to use the computer system, In what cases it would be impossible user-level programs to provide these services? Explain

2.6 2.7 What are the advantages and disadvantages Of using the same system. call interface manipulating both and devices? What is the purpose of the command interpreter? Why is it usually separate the kernel? Would it be possible the user to develop a new command interpreter using the system-call interface provided by the operating system?

C:\\A87394C5\\F2723E28-457D-482E-A856-19FAEB92EECE.files\\image012.png

211 212 2.13 2.14 It is difficult to achieve a layered approach if two compentents of the operating system are dependent on each other. Identify a scenario in which it is how to layer two system components that require tight coupling of their functionalities. What is the main advantage Of the microkernel approach to System design? How do user programs and system services interact in a microkcrncl architecture? What are the disadvantages of using microkernel approach? In what ways is the modular kernel approach similar to the layered approach? In what ways does it differ from the layered approach? What is the main advantage for an operating-system designer Of using a Virtual-machine architecture? What is the main advantage a user?