25-Comp-A5 Operating Systems · December 2017
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
Given. Five processes, single CPU burst each, no I/O.
| Process | Arrival time (s) | Execution time (s) |
|---|---|---|
| Proc1 | 2 | 14 |
| Proc2 | 4 | 7 |
| Proc3 | 6 | 21 |
| Proc4 | 8 | 2 |
| Proc5 | 10 | 1 |
Find. (i) the lowest mean turnaround time any non-preemptive strategy could achieve; (ii) mean turnaround under FCFS.
Approach. (i) is a "best possible schedule" question, not "what does greedy SJF give" — with only 5 jobs every release-respecting non-preemptive order can be searched exhaustively for the true minimum. (ii) simply dispatches jobs in arrival order, idling the CPU whenever the queue is empty.
(ii) FCFS dispatch trace. Jobs run strictly in arrival order 1,2,3,4,5; the CPU is never idle once Proc1 arrives at $t=2$.
| Process | Start | Finish | Turnaround |
|---|---|---|---|
| Proc1 | 2 | 16 | 16−2 = 14 |
| Proc2 | 16 | 23 | 23−4 = 19 |
| Proc3 | 23 | 44 | 44−6 = 38 |
| Proc4 | 44 | 46 | 46−8 = 38 |
| Proc5 | 46 | 47 | 47−10 = 37 |
$$\boxed{\overline{TT}_{\text{FCFS}}=\dfrac{14+19+38+38+37}{5}=\dfrac{146}{5}=29.2\ \text{s}}$$ FCFS is nearly double the achievable optimum (16.8 s) here because it lets the long Proc3 (21 s) and the earlier-arriving Proc1 (14 s) run before the much shorter Proc4/Proc5, exactly the "convoy effect" FCFS is known for.
| Quantity | Value |
|---|---|
| Minimum mean turnaround, any non-preemptive strategy | 16.8 s |
| Mean turnaround, FCFS | 29.2 s |
(b) A multiple-queue technique approximating Optimal (SJF/SRTF) scheduling. The true Optimal (SJF for non-preemptive, SRTF for preemptive) strategy needs to know each job's remaining CPU-burst length in advance, which is not knowable at admission time. The Multilevel Feedback Queue (MLFQ) approximates it without oracle knowledge by using a job's observed behaviour as a proxy for its length. The scheduler maintains several ready queues ranked by priority, each with progressively longer time quanta (e.g. $Q_0$: 8 ms, $Q_1$: 16 ms, $Q_2$: 32 ms, $Q_3$: FCFS). A new job enters the highest-priority queue $Q_0$. If it finishes within that queue's quantum, it is a short (CPU-bound-light or I/O-bound) job and departs having received the fastest possible service — exactly what SRTF would have given it. If it uses the full quantum without finishing, the scheduler infers it is a longer job and demotes it to the next queue down, which has a longer quantum but lower priority, so it interferes less with the short jobs still arriving at $Q_0$. This repeats, so a job's queue level converges to reflect its actual burst length: short jobs are skimmed off quickly at high priority (mimicking SJF/SRTF favouring short jobs), while long, CPU-bound jobs sink to the lowest, FCFS-like queue where they no longer block newer short arrivals. Because higher queues are always scanned before lower ones, a steady stream of short jobs can, in principle, starve the lowest queue — most MLFQ implementations add periodic priority boosts (moving all jobs back to $Q_0$ after a fixed interval) to bound this.
(c) Starvation in a real-time system. Real-time schedulers (e.g. Rate-Monotonic or fixed static-priority scheduling) assign the highest priority to the task with the tightest deadline/period and always run the highest-priority ready task, preempting lower-priority ones. Starvation occurs when a task's priority is low enough, and the higher-priority workload dense enough, that it is never actually given the CPU, even though it is always ready. Two concrete mechanisms: (1) Priority-based CPU starvation — in a Rate-Monotonic system with several high-frequency periodic tasks (e.g. a 1 ms sensor-sampling task and a 5 ms control-loop task) that together consume nearly 100% of CPU capacity, a low-frequency background task (e.g. a 500 ms logging task) may never find a gap, because every time it is ready to run, one of the shorter-period tasks has already become ready again and preempts it — the low-priority task is perpetually deferred, i.e. starved, even though it is schedulable in isolation. (2) Resource-based starvation (priority inversion feeding starvation) — if a low-priority task holds a mutex/semaphore that a high-priority task needs, and a stream of medium-priority tasks keeps preempting the low-priority holder before it can finish and release the lock, the high-priority task is indefinitely starved of the resource despite having top CPU priority (the classic unbounded priority-inversion scenario, mitigated in practice by priority inheritance or priority-ceiling protocols).