Operating System Structure#
Operating-System Services#

Operating-System Services
- User interface (UI): 給 User 下指令
- Graphic user interface (GUI): 圖形化介面
- Program Execution:
- Process 的 normal/abnormal interrupt
- load program to memory
- I/O Operation
- File-System Manipulation
- 包含 access management
- Communication
- Maybe in share memory or bus
- Error Detection
- Resource Allocation
- Accounting (Logging)
- 紀錄
- Protection and Security
User and Operating-System Interface#
- Command interpreters:
- Shell 就是一種直譯器
- Shell script 就是 command 的組合
- GUI
- Application Programming Interface (API)
System call#
- System call 也是一種 OS 提供的 Interface
Application Programming Interface (API)#
- 為了 portability,通常不直接 call system call,不然有可能出問題
- Windows 裡用
CreateProcess()創建,但其實他不是 System call 他會呼叫NTCreateProcess
- Windows 裡用
System-Call Interface#

- 用查表的方法最快,在 kernel 裡有個 table 去到指定 system call 位置,執行後,透過 interface 回傳
- Caller 不需要知道底層在做啥,不然效率太低了
Parameter Passing#
- In register
- In memory
- address 當作
- Linux 用 1&2 combine (5 個以上用 approach 2)
- In stack (資料量更大)
Type of System call#
- Process Control
- create process, terminate process
- load, execute
- get process attributes, set process attributes
- wait event, signal event
- allocate and free memory
- end, abort
- Debugger
- Lock shared data
- File management
- create file, delete file
- open, close
- read, write, reposition
- get file attributes, 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 process, file, or device attributes
- set process, file, or device attributes
- Communications
- create, delete communication connection
- send, receive messages
- transfer status information
- attach or detach remote devices
- Message-passing model and shared-memory model
- Protection
- get file permissions, set file permissions

Type of System call
Linkers & Loaders#
- Compiler 會把 program compile 成一個 Relocatable Object File
- Linker 會把 Object File 跟其他 Obj file 去 combine 成一個 executable file
- 最後真正執行的是 Loader 會把其他 DLL (Dynamic Link Library) 合併進來,load 到 memory 裡
DLL 的出現是希望 executable file 不要太大
- 中間會有 Relocation 這個重新分配記憶體位置的步驟

Operating-System Structure#
Monolithic Structure#
-
Simple (單純) but not necessarily easy
- 所有功能都是同地位,System call 跟 hardware 都包在一起
- Traditional Unix System Structure

Monolithic Structure 2
- Linux Structure

Layered Approach#
- Network
- 只能碰到自己的上層跟下層,越界碰不到

Microkernels#
- Kernel 要極小,除了最基本的其他都給 User mode 實現
- 安全,extendable 但 not efficient
- 用 Message Passing 傳資料

Microkernels
Modules#
- Loadable kernel modules (LKMs)
- Kernel 有基本功能
- Dynamic 的去加入一些東西
- 現在的系統通常都有實現這件事