Chapter 6 - Mechanism: Limited Direct Execution Flashcards
what is direct execution
OS runs your program directly on the CPU without emulation or interpretation
why is direct execution fast
almost nothing between program and CPU
why is it called limited direct execution
programs run directly on the cpu, but OS limits what they can do for safety and fairness
What is time sharing?
The OS switches between programs so they share CPU fairly and efficiently.
What are the goals of limited direct execution?
Fast execution, security, and hardware sharing
What is user mode vs. kernel mode?
- User mode: Limited privileges (can’t access hardware or OS memory)
- Kernel mode: Full access to system resources
Why do we need two CPU modes?
To prevent user programs from performing dangerous or privileged operations
How does a user program perform a privileged action?
triggers a trap, switching to kernel mode to run OS code - save all neccessary info on the kernel stack
what is a trap table
A table that tells the CPU what code to run for each kind of trap
How can the OS regain control of the CPU from a running process?
Cooperative approach + Non-Cooperative approach
cooperative approach
Process gives up control voluntarily (by a system call or crashing)
non-cooperative approach
The OS uses a timer interrupt
what is a timer interrupt
pauses the running program and gives control to the OS
What is a context switch?
The process of saving one process’s state and loading another’s
what happens during context switch
save current process registers and program counter - load next prosess saved state - resume with return-from-trap
What’s the difference between hardware and software state saving?
- Timer interrupt: Saves user registers (hardware), stored in kernel stack
- Context switch: Saves kernel registers (software), stored in process structure
What is the role of the scheduler?
It decides which process should run next after a trap or interrupt
Define; trap, system call, return-from-trap
- trap: CPU switches to kernel mode due to an event
- system call: a request from a user program for a privileged operation
- return-from-trap: instructions that resumes a user process and switches back to user mode
concurrency
when multiple things happen at the same time
What is a downside of disabling interrupts for too long?
The system might miss important events like keyboard inputs or network packets
Why does the OS use locks?
To prevent multiple parts of the kernel from accessing shared data at the same time
What is careful interrupt nesting?
Allowing high-priority interrupts while blocking lower-priority ones — used for safety and responsiveness