Operating Systems ยท Unit 4
CPU Scheduling
Exam-focused notes for CPU Scheduling (Operating Systems, BIT204): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.
CPU Scheduling in short
CPU scheduling decides which ready process gets the CPU next. Good scheduling keeps the CPU busy and gives users fast responses. This chapter covers the main algorithms and how to calculate their times.
What this unit covers
- Scheduling objectives and criteria
- FIFO scheduling algorithm
- Shortest Job First scheduling
- Priority scheduling
- Round Robin scheduling
- Turnaround time calculation
- Waiting time calculation
- Multiple queue scheduling
Turnaround time calculation
2080 ยท 10 marks
CPU Scheduling Analysis
Find Average waiting time and turn-around time for the following example using FIFO, SRTF and Round Robin scheduling algorithm. Assume quantum as 4 ms.
| Process id | Arrival time | Burst time (ms) |
|---|---|---|
| P1 | 0 | 8 |
| P2 | 1 | 5 |
| P3 | 1 | 10 |
| P4 | 2 | 13 |
| P5 | 2 | 17 |
[10]
Round Robin scheduling
2078 ยท 5 marks
CPU Scheduling Analysis
Consider the following set of processes, with the length of CPU burst time given in milliseconds. The processes are assumed to have arrived in the order A, B, C and D all at time 0. What is the turnaround time and waiting time for the scheduling algorithms, RR (quantum = 3) and Priority Algorithm.
| Process | CPU Burst | Priority |
|---|---|---|
| A | 8 | 3 |
| B | 9 | 1 (Lowest) |
| C | 10 | 2 |
| D | 6 | 4 (Highest) |
[5]
Show solved answerHide answer
CPU Scheduling: RR (q=3) and Priority
Given
| Process | CPU Burst | Priority |
|---|---|---|
| A | 8 | 3 |
| B | 9 | 1 (Lowest) |
| C | 10 | 2 |
| D | 6 | 4 (Highest) |
All arrive at time 0, in order A, B, C, D.
Formulas: $TAT = CT - AT$, $WT = TAT - Burst$.
Solution
1. Round Robin (Quantum = 3)
Ready queue starts: A, B, C, D. A process that still has remaining burst rejoins the tail of the queue after its slice.
Tracing execution (remaining bursts A=8, B=9, C=10, D=6):
| Slot | Proc | Range | Remaining after |
|---|---|---|---|
| 1 | A | 0-3 | A=5 |
| 2 | B | 3-6 | B=6 |
| 3 | C | 6-9 | C=7 |
| 4 | D | 9-12 | D=3 |
| 5 | A | 12-15 | A=2 |
| 6 | B | 15-18 | B=3 |
| 7 | C | 18-21 | C=4 |
| 8 | D | 21-24 | D=0 โ |
| 9 | A | 24-26 | A=0 โ |
| 10 | B | 26-29 | B=0 โ |
| 11 | C | 29-32 | C=1 |
| 12 | C | 32-33 | C=0 โ |
Gantt:
| A | B | C | D | A | B | C | D | A | B | C | C |
0 3 6 9 12 15 18 21 24 26 29 32 33
| Process | Burst | CT | TAT | WT |
|---|---|---|---|---|
| A | 8 | 26 | 26 | 18 |
| B | 9 | 29 | 29 | 20 |
| C | 10 | 33 | 33 | 23 |
| D | 6 | 24 | 24 | 18 |
$$\text{Avg TAT} = \frac{26+29+33+24}{4} = \frac{112}{4} = 28 \text{ ms}$$ $$\text{Avg WT} = \frac{18+20+23+18}{4} = \frac{79}{4} = 19.75 \text{ ms}$$
2. Priority Scheduling (Non-Preemptive)
Higher number = higher priority. Execution order: D (4) โ A (3) โ C (2) โ B (1)
Gantt:
| D | A | C | B |
0 6 14 24 33
| Process | Burst | CT | TAT | WT |
|---|---|---|---|---|
| D | 6 | 6 | 6 | 0 |
| A | 8 | 14 | 14 | 6 |
| C | 10 | 24 | 24 | 14 |
| B | 9 | 33 | 33 | 24 |
$$\text{Avg TAT} = \frac{6+14+24+33}{4} = \frac{77}{4} = 19.25 \text{ ms}$$ $$\text{Avg WT} = \frac{0+6+14+24}{4} = \frac{44}{4} = 11 \text{ ms}$$
Summary
| Algorithm | Avg TAT | Avg WT |
|---|---|---|
| RR (q=3) | 28 ms | 19.75 ms |
| Priority | 19.25 ms | 11 ms |
0 ยท 5 marks
CPU Scheduling Analysis
Consider the following set of processes, with the length of CPU burst time given in milliseconds.
| Processes | CPU Burst | Priority |
|---|---|---|
| A | 8 | 3 |
| B | 13 | 1 (Lowest) |
| C | 19 | 2 |
| D | 3 | 4 (Highest) |
The processes are assumed to have arrived in the order A, B, C and D all at time 0. What is the turnaround time and waiting time for the scheduling algorithms, RR (quantum = 5) and Priority Algorithm?
[5]
Show solved answerHide answer
CPU Scheduling: RR (quantum = 5) and Priority
Given
| Process | CPU Burst (ms) | Priority |
|---|---|---|
| A | 8 | 3 |
| B | 13 | 1 (Lowest) |
| C | 19 | 2 |
| D | 3 | 4 (Highest) |
Arrival: all at time 0, order A, B, C, D. Total burst = $8+13+19+3 = 43$ ms.
Solution
Part 1: Round Robin (q = 5)
Ready queue starts A, B, C, D. Track remaining bursts.
| Slot | Proc | Start | End | Remaining after |
|---|---|---|---|---|
| 1 | A | 0 | 5 | 3 |
| 2 | B | 5 | 10 | 8 |
| 3 | C | 10 | 15 | 14 |
| 4 | D | 15 | 18 | 0 (needs 3) |
| 5 | A | 18 | 21 | 0 (needs 3) |
| 6 | B | 21 | 26 | 3 |
| 7 | C | 26 | 31 | 9 |
| 8 | B | 31 | 34 | 0 (needs 3) |
| 9 | C | 34 | 39 | 4 |
| 10 | C | 39 | 43 | 0 |
Gantt:
| A | B | C | D | A | B | C | B | C | C |
0 5 10 15 18 21 26 31 34 39 43
Completion times: A = 21, B = 34, C = 43, D = 18
Turnaround (TAT = Completion โ 0):
| Proc | TAT | WT = TAT โ Burst |
|---|---|---|
| A | 21 | 21 โ 8 = 13 |
| B | 34 | 34 โ 13 = 21 |
| C | 43 | 43 โ 19 = 24 |
| D | 18 | 18 โ 3 = 15 |
$$\text{Avg TAT} = \frac{21+34+43+18}{4} = \frac{116}{4} = 29 \text{ ms}$$
$$\text{Avg WT} = \frac{13+21+24+15}{4} = \frac{73}{4} = 18.25 \text{ ms}$$
Part 2: Priority Scheduling (Non-preemptive)
Highest priority number runs first: D(4) โ A(3) โ C(2) โ B(1)
Gantt:
| D | A | C | B |
0 3 11 30 43
| Proc | Completion | TAT | WT = TAT โ Burst |
|---|---|---|---|
| D | 3 | 3 | 0 |
| A | 11 | 11 | 3 |
| C | 30 | 30 | 11 |
| B | 43 | 43 | 30 |
$$\text{Avg TAT} = \frac{3+11+30+43}{4} = \frac{87}{4} = 21.75 \text{ ms}$$
$$\text{Avg WT} = \frac{0+3+11+30}{4} = \frac{44}{4} = 11 \text{ ms}$$
Summary
| Algorithm | Avg TAT | Avg WT |
|---|---|---|
| RR (q = 5) | 29 ms | 18.25 ms |
| Priority | 21.75 ms | 11 ms |
All values confirmed correct.
Multiple queue scheduling
0 ยท 5 marks
Why do we need multiple queues in process scheduling? What is the significance of TLB? [5]
Make Unit 4 stick
Practice BIT204 with flashcards & quizzes