Operating Systems & Concurrency: Process Scheduling, Deadlocks & Virtual Memory
Operating Systems represents 5% of the overall NSCT score. Because the questions are highly standardized, scoring 5/5 in this domain requires mastering four key areas: process scheduling, synchronization primitives, deadlock conditions, and virtual memory paging.
1. Process States & CPU Scheduling
A process transitions through: New $ ightarrow$ Ready $ ightarrow$ Running $ ightarrow$ Waiting (Blocked) $ ightarrow$ Terminated.
CPU Scheduling Algorithms
- First-Come, First-Served (FCFS): Non-preemptive. Suffers from the Convoy Effect where short processes wait behind long CPU-burst processes.
- Shortest Job First (SJF): Optimal minimum average waiting time. Impossible to implement perfectly in general OS because next CPU burst length cannot be known in advance.
- Shortest Remaining Time First (SRTF): Preemptive version of SJF.
- Round Robin (RR): Preemptive scheduling designed for time-sharing systems using a Time Quantum ($q$).
- If $q$ is extremely large, RR degenerates to FCFS.
- If $q$ is extremely small, excessive context switching overhead degrades throughput.
- Priority Scheduling: Can cause starvation (low priority processes never run). Solution: Aging (gradually increasing priority of processes waiting for long periods).
2. Process Synchronization & Critical Section Problem
Any valid solution to the Critical Section problem must satisfy three requirements:
- Mutual Exclusion: If process $P_i$ is executing in its critical section, no other processes can be in theirs.
- Progress: If no process is in its critical section and some processes wish to enter, only those not in their remainder section can participate in deciding who enters next.
- Bounded Waiting: There must be a bound on the number of times other processes are allowed to enter their critical sections after a process has requested entry.
Mutex vs Counting Semaphore
- Mutex: Binary lock (0 or 1) owned by a single thread. Only the thread that acquired the mutex can release it.
- Counting Semaphore: Integer counter initialized to resource count $N$.
wait()/P(): Decrements counter. If counter $< 0$, process blocks.signal()/V(): Increments counter. If counter $\le 0$, wakes a waiting process.
3. Deadlocks & The 4 Coffman Conditions
A deadlock can occur if and only if all four conditions hold simultaneously:
- Mutual Exclusion: At least one resource must be held in a non-shareable mode.
- Hold and Wait: A process must be holding at least one resource and waiting to acquire additional resources held by other processes.
- No Preemption: Resources cannot be forcibly preempted; they are released only voluntarily by the holding process.
- Circular Wait: A closed chain of processes exists where each process holds resources needed by the next process in the chain.
Banker’s Algorithm: Used for Deadlock Avoidance by ensuring the system remains in a Safe State before granting resource allocation requests.
4. Virtual Memory & Page Replacement Algorithms
Virtual memory maps logical addresses to physical memory frames via a Page Table.
- Page Fault: Occurs when a referenced virtual page is not currently mapped into physical RAM (valid bit = 0), triggering an OS interrupt to fetch the page from disk.
- Thrashing: Occurs when the system spends more time servicing page faults and swapping pages than executing actual application code.
Common Page Replacement Algorithms
- FIFO (First-In, First-Out): Replaces oldest page. Suffers from Belady’s Anomaly (allocating more physical page frames can paradoxically increase the number of page faults!).
- LRU (Least Recently Used): Replaces the page that has not been used for the longest period of time. Immune to Belady's Anomaly (Stack algorithm).
- Optimal (OPT / MIN): Replaces the page that will not be used for the longest period in the future. Theoretical upper bound benchmark.
Content structured in accordance with Higher Education Commission (HEC) Computing National Curriculum, PSEB TechLift competency standards, and the 120-minute Virtual University assessment model.