Process: A running program identified by a PID
- Has a virtual CPU
- Has a virtual address space (code & data & execution stack), PC (program counter) pointer
- Set of registers
- Set of OS resources (open files, connections, signals, etc.)
Process Control Block (PCB): Where OS store data about each processes
- State, PC, registers, scheduling priority, memory page tables, resource usage, IO list
Starting Process:
- Create new process PCB + address space
- Load executable (“ready”)
- Dispatch process (”running”)
Process Lifecycle
- Process Lifecycle: New → {(Blocked →) Ready ↔ Running (→ Blocked)} → Exit
State Queues: Queue of processes in different states
Context Switch: Switch cpu core from one running process to another ready process
- Set to kernel mode
- Save registers & PC (A) to kernel stack
- Jump to trap handler
- Restore registers & PC (B) from kernel stack
- Set to user mode
Context Switch Causes
- Voluntary: Current process
yield()
- Blocked Calls: Current process request a blocked system resource (e.g.
read()
)
- Timer Interrupt: Timer handler decide to switch process
Creation & Termination
Parent Process: Every process is created by a parent (up to PID1 - init)
- fork: Create a subprocess with a copy of the address space
- exec: Replace the code in the current process with new code
Process Destruction: exit()
releases all resources
- Stop process → free memory → turn into zombie process → switch.
- Zombie Process: Keep exit code for parent to collect