Process and Kernel
Topic :
- The process abstraction
- Dual-mode operation
- Safe control transfer
Process 是对运行程序的抽象。a process is an instance of a program. (有一个 process control block 储存了一个特定 process 的所有信息)
而 Kernel 与 program 的关系就像浏览器与第三方插件的关系一样。
为了阻止一个 process 做坏事(如覆盖其它 process 的data),最直接的想法是:Kernel 检查 process 中的每一条指令,但这样速度比较慢,于是设想是否有这样一种机制:允许一些安全的指令直接执行,而危险的指令需要检查。在处理中增加一个一位(mode bit)的寄存器, 用于区分 kernel mode 和 user mode。接下来的问题就是:什么时候两种 mode 互相切换。(safe control transfer)
Safe control transfer
User to kernel mode:Exception,Interrupt,System calls
Kernel to user mode:New process,Resume after exception,interrupt or system call,Switch to a different process, User-level upcall
Exception & Interrupt (如何执行看数字 x86 实例)
有一个 Interrupt vector:an array of process with each entry pointing to the first instruction of a different handler procedure in the kernel (类似函数调用,有一个 Interrupt stack,甚至许多系统给每个进程\线程 一个 kernel stack)
Interrupt masking
System call
System call provide the illusion that the operating system kernel is simply a set of library routines, avaiable for use by user programs: User level program can issue a system call by execute the trap instruction (有时利用 Interrupt) to transfer control to the operating system level.
User-level upcall
一个思想:virtualize some part of the operating system kernel, so that applications can behave more like operating system.
virtualized interrupts and exceptions 称作 upcall,在 Unix 称作 Signal
Upcall 的出现是因为就像 kernel 会接受一个 exception/interrupt 然后执行特定事件一样,application 也有接受特定 Signal 然后执行特定事件的需求(比如在 shell 中 ctrl + c)