Chapter 4

CPU scheduling

Build the timeline before computing averages. The scheduling policy chooses among ready processes; I/O completion, arrival and quantum expiration change that set. A formula is useful only after the correct completion and first-dispatch times are known.

4.1 Time measures and throughput

Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark

4.2 FCFS, SJF and SRTF

Past papers · CS 2014–2026 (23 papers): 12 questions, 19 marks

FCFS selects the oldest ready arrival without preemption. Nonpreemptive SJF selects the shortest next CPU burst among ready jobs. SRTF selects the smallest remaining burst and can preempt at an arrival or other ready event.

For jobs all available together, zero overhead and known burst lengths, SJF minimises average waiting and turnaround. With arbitrary future arrivals, a nonpreemptive scheduler allowed to idle deliberately can beat the always-busy SJF choice. SRTF is the preemptive counterpart when remaining service is known and preemption is free.

The SRTF example records every preemption and completion boundary.The SRTF example records every preemption and completion boundary.

4.3 Round robin and context-switch cost

Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks

Round robin (RR) serves the head of the ready queue for at most one quantum. A finishing or blocking process leaves before the quantum ends. An unfinished process goes to the tail. Specify how arrivals exactly at a quantum boundary are ordered relative to the requeued process.

4.4 Priority, feedback and starvation

Past papers · CS 2014–2026 (23 papers): 4 questions, 7 marks

For periodic tasks, create a new job at every release time, including releases while an earlier job is executing. Use the supplied period-based priorities and simulate preemptions; no schedulability bound is needed to find one job's completion.

With several CPUs, draw one timeline per CPU. At each completion or arrival, dispatch the best eligible waiting process under that CPU's rule; remove it from the common waiting set immediately. A single-threaded process cannot occupy two CPUs simultaneously. Waiting time still measures time ready but running on none of them.

Priority scheduling selects the highest-priority ready process; smaller numeric priority values are not universally higher. It can be preemptive or nonpreemptive. Aging raises a waiting process's effective priority to reduce starvation.

If a question specifies longest-job or longest-remaining-time scheduling, follow that selection rule literally. For LRTF, two remaining times can become equal during execution; the stated timer granularity and tie rule determine subsequent switches.

A multilevel queue fixes a process's queue class; multilevel feedback allows movement. Track both the rule within each queue and the rule between queues. A high-priority arrival may preempt a lower-queue job even if the lower queue uses FCFS internally. Priority inversion occurs when a high-priority thread waits for a lock held by a lower-priority thread; priority inheritance temporarily raises the holder's priority.

PolicyTypical benefitFailure to remember
FCFSSimple arrival orderConvoy effect behind a long burst
SJF/SRTFLow average delay under their modelLong jobs can starve with continuing short arrivals
RRRegular opportunities to runSmall quantum increases switching overhead
PriorityUrgent work can run earlyLow priorities need fairness policy
Feedback queuesAdapt to observed behaviourExact promotion/demotion rules determine results

4.5 Predicting the next burst

4.6 Coupled CPU and I/O bursts

Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks

Keep a separate timeline for each device. A process that finishes a CPU burst joins its device queue; after I/O completion it joins the ready queue. A single FCFS device services one request at a time, while multiple independent devices can work concurrently. The next simulation event is the earliest arrival, CPU completion, I/O completion or quantum expiration.

Last-minute recall

  • Turnaround ends at completion; response ends at the specified first response.
  • Subtract total blocked time when converting turnaround into ready waiting.
  • SJF looks at the next burst; SRTF looks at remaining service.
  • RR is a queue simulation, not repeated sorting by arrival time.
  • Distinguish useful utilisation from utilisation including overhead.
  • Priority numbering and simultaneous-event order must be stated.
  • I/O completion makes a process eligible; it need not run immediately.

Revise offline: the whole Operating System handbook as one PDF

50 pages · 2.0 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections