###### tags: `OS`
# 1062 - Operating System 期中考複習
## 1. Please explain following terms
#### a. Multiprogramming
* 為了使得**多個程式可以同時執行而發展的技術**,他可以**使得CPU一直處於忙碌的狀態**,而不會等待程式進行週邊的運作,進而**提升電腦系統的整體效率**。
#### b. Bootstrap program
* 負責把OS核心載入記憶體,並且執行核心程式。
#### c. DMA
* Direct Memory Access
* 他允許某些電腦內部的硬體子系統,可以獨立地直接讀寫系統記憶體,而不須CPU介入處理。
## 2. Please describe interrupt and trap.
* Trap
* An exception in a user program. It's caused by division by zero, invalid memory access, etc.
* Interrupt
* Generated by the hardware such as hard disk, I/O system
## 3. There are kinds of storage types like 'magnetic disk', 'cache', 'tapes', 'optical disk', 'register' and 'main memory'. Compare the access speed above in arranged order.
**From fast to slow**
* register > cache > main memory > magnetic disk > optical disk > tapes
## 4. Explain what is "User Mode" and "Kernel Mode"? And why Operating System needs Kernel Mode?
* User mode is to separate the operation of hardware from OS. Kernel mode can do almost all operations of computer hardware and system functions. If a application running on user mode needs to access hardware, it is necessary calling the "system call" to enter kernel mode.
* In order to strengthen security of OS.
## 5. Please described the advantage of using a virtual machine? (At least 2 points of view)
* Resource management
* Providing an experiment environment
* Share the same hardware
* Protect from each other
* Some sharing of files can be permitted, controlled
## 6. What are the main advantages of the micro-kernel approach to system design? (At least 2 points of view)
* 擴充簡單
* 移植簡單
* 更安全
* 更可靠
## 7. What is context switch and how can it work?
* 當CPU切換至其他process,透過context switch,系統會儲存當前process狀態(存入PCB)並載入新的process的PCB。
## 8. Please describe the differences between thread and process.
* Process
* OS分配資源的基本單位
* Thread
* CPU執行程序、排程的基本單位
## 9. Please describe PCB (process control block) and what information should be included in PCB? (at least list 3 points)
* Process state
* Program counter
* CPU registers
* CPU scheduling information
* Memory management information
* Accounting information
* I/O status information
## 10. Draw the state diagram of processes, and explain each state.

## 11. Please describe `fork()` and `exec()`.
* fork
* system call creates new process
* exec
* system call used after a fork to replace the process's memory space with a new program
## 12. Compare to single thread process, what are the benefits of multi-threading? (a least 3 points of view)
* Responsiveness
* Resource sharing
* Economy
* Scalability
## 13. Consider the following set of processes to solve the following two questions:

#### a. The Gantt chart for preemptive priority scheduling algorithm is: (Low number => high priority)

#### b. Receives writes, what are the turnaround time of each process?
* P1: 28
* P2: 16
* P3: 5
* P4: 11
* P5: 16
## 14. Please draw the Gantt charts and calculate the average waiting time of the following processes for the problems shown below.

#### a. First come first served (FCFS)

* average waiting time = 15 / 5 = 3
#### b. Round-Robin, time quantum = 2

* average waiting time = 20 / 5 = 4
#### c. Preemptive shortest-remaining-time-first

* average waiting time = 12 / 5 = 2.4
## 15. One important problem with priority CPU scheduling algorithm is the starvation. Explain the "process of starvation" and how "aging" can be used to prevent it?
* Starvation
* Process因為長期無法取得所需資源(如因為優先權過低),導致無法完成工作、indefinite blocking(無限期阻塞)
* Aging
* 隨著process待在系統的時間增加,系統也逐步調高其優先權。