https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf
Processes
- Process: A running program
- The program itself is “lifeless”: Just code sitting on a disk
- To allow a computer to run more programs than CPUs “concurrently”, we “virtualize” the CPU: Each program “sees” a CPU and treats it as if it is the only program running on that CPU.
- Time sharing
- Context switch: Changing the program running on a CPU.
- How would you explain Mechanism vs. Policy?
- Mechanism: How to make something happen
- Policy: The choice of what to do.
- Apply mechanism vs policy to time sharing a CPU.
- Mechanism is the stuff that needs to happen so that one process can replace another on the CPU without either process knowing it happens.
- Policy includes things like choosing when to do a context switch.
Process State
- If we want to be able to switch processes, what all do we
need to preserve?
- Memory state (address space)
- General purpose registers
- Special purpose registers (Program counter, stack pointer, flags)
- Open file handles
- Current working directory
- Other stuff
Process API
- What operations does an OS need to be able to take on processes?
- Create
- Destroy
- Wait
- Status
- Misc others (e.g., suspend)
Process Creation
- Load machine code from disk into memory
- Initialize any static data e.g., global constants.
- Set up the stack and heap
- Set up I/O (stdin, stdout)
- Set PC to first instruction in
main
Process States
- Running
- Ready
- Blocked
Data Structures
- OS needs to maintain a list of processes.
- For each process, it needs to track the status, and the “Process State” information listed above.
- Show Figure 4.5 on p8 https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf