Operating System Note 01/24
Two abstractions: processes, files.
Process is a program in execution.
Virtualize CPU
- Challenges
Efficiency - Mechanism
Limited Directed Execution - User mode, Kernel mode
- User mode can execute a system call to perform restricted operation
- Execute a trap instruction, jumps into kernel and raise privilege level, when finished, OS calls a return-from-trap instruction, reduce privilege level
- Switching between processes
How to regain control of the CPU? (Since OS is not running when a process running on the CPU)- Wait for system calls (Cooperative approach)
- OS takes control (Non-cooperative): A timer interrupt
- Saving and Restoring Context
Decision made by scheduler. If decide to switch, executes context switch.- Context switch
OS saves register values for the current running process, and restore for the soon-to-be-executing process.
For timer interrupt, the user registers are implicitly saved by hardware.
For OS switch, the kernel registers are explicitly saved by software.
- Context switch
Between OS & Hardware
- Protection
- CPU modes - User, Kernel (privileged instruction) (monitor, supervisor)
- Base + limit registers base <= address < limit base
- Interrupts (timer) /Allow sys do sth else/
- stop current execution
- handle interrupt
- resume current execution
- e.g while (1); How do sys regain control?
Set a timer, when counts to 0, kernel sends an interrupt - Can masking certain interrupts
- CPU can have status disable&enable
- System calls -> Software interrupt
- Interrupt - btw instructions
- Exception - within an instruction
- Trap - go to the OS