1. Process Management & CPU Scheduling
A process moves through states: new → ready → running → (waiting ↔ running) → terminated, tracked via a Process Control Block (PCB). Scheduling algorithms: FCFS (First-Come-First-Served — simple, but suffers the convoy effect where a long process delays everyone behind it); SJF (Shortest Job First — optimal for minimising average waiting time, but needs to know burst times in advance and can starve long processes); Round Robin (fixed time quantum per process, cycling through a ready queue — fair, good for time-sharing systems, but performance is very sensitive to quantum size); Priority scheduling (highest-priority process runs first, can starve low-priority processes without aging, which gradually raises a waiting process's priority).
Turnaround time = completion time − arrival time. Waiting time = turnaround time − burst time. These two formulas are the basis of nearly every scheduling numeric problem — get comfortable building a Gantt chart from a process table first, then reading times off it directly rather than trying to compute them algebraically from scratch each time.
Process Burst Time
P1 6
P2 8
P3 7
P4 3
SJF execution order (shortest burst first): P4, P1, P3, P2
Gantt chart: | P4 | P1 | P3 | P2 |
0 3 9 16 24
Completion: P4=3 P1=9 P3=16 P2=24
Turnaround: P4=3 P1=9 P3=16 P2=24 (arrival=0, so turnaround=completion)
Waiting: P4=0 P1=3 P3=9 P2=16
Average waiting time = (0+3+9+16)/4 = 7
Always build the Gantt chart first, read off each process's exact completion time directly from it, and only then apply turnaround = completion − arrival and waiting = turnaround − burst — computing these formulas without a Gantt chart in front of you is where most scheduling errors happen.
2. Process Synchronization & Deadlocks
A race condition occurs when multiple processes/threads access shared data concurrently and the outcome depends on timing. A critical section is the code segment accessing shared data that must run with mutual exclusion. Semaphores (a counter with atomic wait/signal, or P/V, operations) and mutex locks are the standard synchronization primitives; the classic Producer-Consumer, Readers-Writers and Dining Philosophers problems are the standard scenarios used to test whether you understand how to apply them correctly.
Deadlock requires all four Coffman conditions simultaneously: mutual exclusion (resources aren't shareable), hold and wait (a process holds a resource while waiting for another), no preemption (resources can't be forcibly taken away), and circular wait (a cycle of processes each waiting on the next). Breaking any single one of these four prevents deadlock — which is exactly the principle behind deadlock prevention strategies. Deadlock avoidance takes a different approach: the Banker's Algorithm checks, before granting a resource request, whether the resulting state is still "safe" (a sequence exists in which all processes can eventually finish), refusing requests that would lead to an unsafe state.
3. Memory Management & File Systems
Paging divides physical memory into fixed-size frames and logical memory into same-sized pages, eliminating external fragmentation (but allowing internal fragmentation within the last page). Segmentation divides a program into logical, variable-sized units (code, stack, heap) matching how a programmer thinks about the program, but reintroduces external fragmentation. Address translation uses a page table (with a TLB, translation look-aside buffer, caching recent translations for speed).
When physical memory is full and a new page must be brought in, a page-replacement algorithm decides what to evict: FIFO (evict the oldest-loaded page — simple, but can suffer Belady's anomaly, where adding more frames actually increases page faults), LRU (evict the Least Recently Used page — a strong practical approximation of the unimplementable optimal algorithm, which would evict whichever page is used furthest in the future), and Optimal (the theoretical best, used as a benchmark, not implementable since it requires future knowledge).
Paging solves external fragmentation but allows internal fragmentation (wasted space within the last, partially-used frame); segmentation matches logical program structure but reintroduces external fragmentation — knowing which fragmentation type goes with which scheme is one of the single most repeated OS exam facts.
4. Hands-on Exercise
Run a full scheduling comparison and a page-replacement trace
OS numericals are learned by doing full worked examples, not by re-reading algorithm names.
Part 1 — Scheduling:
- Given processes P1(burst=5, arrival=0), P2(burst=3, arrival=1), P3(burst=8, arrival=2), P4(burst=6, arrival=3), compute the average waiting time under FCFS.
- Compute the average waiting time for the same processes under Round Robin with quantum=2.
- State which algorithm gave the lower average waiting time here, and whether that's guaranteed to always be true for any process set.
Part 2 — Page replacement:
- For the reference string 7,0,1,2,0,3,0,4,2,3,0,3,2 with 3 frames, trace FIFO page replacement and count total page faults.
- Trace LRU on the same reference string and frame count, and count its page faults.
- State which algorithm performed better here and by how much.
5. Exam-Style Practice (UGC NET Pattern)
Five NTA-pattern questions on scheduling, deadlock and memory management.
Q1
Which CPU scheduling algorithm is provably optimal for minimising the average waiting time, assuming burst times are known in advance?
A) First-Come-First-Served (FCFS)
B) Shortest Job First (SJF)
C) Round Robin
D) Priority Scheduling
Which CPU scheduling algorithm is provably optimal for minimising the average waiting time, assuming burst times are known in advance?
A) First-Come-First-Served (FCFS)
B) Shortest Job First (SJF)
C) Round Robin
D) Priority Scheduling
Correct answer: B) Shortest Job First (SJF). SJF is provably optimal for minimising average waiting time among non-preemptive scheduling algorithms when burst times are known — its drawback is that it requires that advance knowledge and can starve longer processes.
Q2
Which of the following is NOT one of the four necessary (Coffman) conditions for deadlock?
A) Mutual exclusion
B) Hold and wait
C) Preemption
D) Circular wait
Which of the following is NOT one of the four necessary (Coffman) conditions for deadlock?
A) Mutual exclusion
B) Hold and wait
C) Preemption
D) Circular wait
Correct answer: C) Preemption. The four Coffman conditions are mutual exclusion, hold and wait, NO preemption, and circular wait — the presence of preemption (the ability to forcibly reclaim a resource) actually helps PREVENT deadlock, so it is the negation of a condition, not the condition itself.
Q3
The Banker's Algorithm is a deadlock:
A) Prevention technique, by eliminating the circular wait condition
B) Avoidance technique, by only granting requests that leave the system in a safe state
C) Detection technique, run periodically after deadlock may have occurred
D) Recovery technique, by forcibly terminating a process
The Banker's Algorithm is a deadlock:
A) Prevention technique, by eliminating the circular wait condition
B) Avoidance technique, by only granting requests that leave the system in a safe state
C) Detection technique, run periodically after deadlock may have occurred
D) Recovery technique, by forcibly terminating a process
Correct answer: B) Avoidance technique, by only granting requests that leave the system in a safe state. The Banker's Algorithm is a deadlock avoidance technique — it checks, before granting each resource request, whether doing so leaves the system in a safe state, refusing requests that would not.
Q4
Which memory management scheme divides memory into fixed-size units and eliminates external fragmentation, at the cost of possible internal fragmentation?
A) Segmentation
B) Paging
C) Dynamic partitioning
D) Overlaying
Which memory management scheme divides memory into fixed-size units and eliminates external fragmentation, at the cost of possible internal fragmentation?
A) Segmentation
B) Paging
C) Dynamic partitioning
D) Overlaying
Correct answer: B) Paging. Paging uses fixed-size pages and frames, which eliminates external fragmentation entirely, but can leave some wasted space (internal fragmentation) within the last, partially-filled page of a process.
Q5
In the FIFO page-replacement algorithm, Belady's anomaly refers to the surprising situation where:
A) Increasing the number of available frames increases the number of page faults
B) Decreasing the number of frames decreases the number of page faults
C) The algorithm never causes any page faults at all
D) LRU always performs worse than FIFO
In the FIFO page-replacement algorithm, Belady's anomaly refers to the surprising situation where:
A) Increasing the number of available frames increases the number of page faults
B) Decreasing the number of frames decreases the number of page faults
C) The algorithm never causes any page faults at all
D) LRU always performs worse than FIFO
Correct answer: A) Increasing the number of available frames increases the number of page faults. Belady's anomaly is the counter-intuitive result, specific to FIFO, that adding more physical frames can sometimes actually increase the total number of page faults rather than decreasing them.