Skip to content
Official PYQ · 2024

GATE CS 2024 Set 2 Q27 — CPU Scheduling

Explain with AI

​​​​Consider a single processor system with four processes A, B, C,\text{A, B, C,} and D\text{D}, represented as given below, where for each process the first value is its arrival time, and the second value is its CPU\text{CPU} burst time.

                  A(0,10),B(2,6),C(4,3)\mathrm{A}(0,10), \mathrm{B}(2,6), \mathrm{C}(4,3), and D(6,7)\mathrm{D}(6,7).

Which one of the following options gives the average waiting times when preemptive Shortest Remaining Time First (SRTF)\text{(SRTF)} and Non-Preemptive Shortest Job First (NP-SJF)\text{(NP-SJF)} CPU\text{CPU} scheduling algorithms are applied to the processes?

Choose one option
View worked solution

Answer: B

We can find the average waiting times by simulating both scheduling algorithms using Gantt charts.

1. Preemptive Shortest Remaining Time First (SRTF)

At any scheduling point, the process with the shortest remaining CPU burst time is executed:

  • At t=0t = 0: Only A\text{A} is available (remaining burst = 10). A\text{A} runs.
  • At t=2t = 2: B\text{B} arrives (burst = 6). Remaining burst of A\text{A} is 8. Since 6<86 < 8, B\text{B} preempts A\text{A}.
  • At t=4t = 4: C\text{C} arrives (burst = 3). Remaining burst of B\text{B} is 4. Since 3<43 < 4, C\text{C} preempts B\text{B}.
  • At t=6t = 6: D\text{D} arrives (burst = 7). Remaining burst of C\text{C} is 1. Since 11 is the shortest, C\text{C} continues.
  • At t=7t = 7: C\text{C} finishes. Remaining bursts: B(4),D(7),A(8)\text{B}(4), \text{D}(7), \text{A}(8). B\text{B} runs.
  • At t=11t = 11: B\text{B} finishes. Remaining bursts: D(7),A(8)\text{D}(7), \text{A}(8). D\text{D} runs.
  • At t=18t = 18: D\text{D} finishes. A\text{A} runs.
  • At t=26t = 26: A\text{A} finishes.

SRTF Gantt Chart:

A\text{A}B\text{B}C\text{C}B\text{B}D\text{D}A\text{A}
0 - 22 - 44 - 77 - 1111 - 1818 - 26

Waiting Time (WT = Completion Time - Arrival Time - Burst Time):

  • WT(A)=26−0−10=16\text{WT(A)} = 26 - 0 - 10 = 16
  • WT(B)=11−2−6=3\text{WT(B)} = 11 - 2 - 6 = 3
  • WT(C)=7−4−3=0\text{WT(C)} = 7 - 4 - 3 = 0
  • WT(D)=18−6−7=5\text{WT(D)} = 18 - 6 - 7 = 5

Average WT (SRTF)=16+3+0+54=244=6\text{Average WT (SRTF)} = \frac{16 + 3 + 0 + 5}{4} = \frac{24}{4} = 6

2. Non-Preemptive Shortest Job First (NP-SJF)

Processes run to completion without preemption. At each completion point, the available process with the shortest burst time is selected:

  • At t=0t = 0: Only A\text{A} is available. A\text{A} runs to completion (0 to 10).
  • At t=10t = 10: B(6),C(3),\text{B}(6), \text{C}(3), and D(7)\text{D}(7) have all arrived. C\text{C} has the shortest burst. C\text{C} runs (10 to 13).
  • At t=13t = 13: B(6)\text{B}(6) and D(7)\text{D}(7) are available. B\text{B} runs (13 to 19).
  • At t=19t = 19: D\text{D} runs (19 to 26).

NP-SJF Gantt Chart:

A\text{A}C\text{C}B\text{B}D\text{D}
0 - 1010 - 1313 - 1919 - 26

Waiting Time (WT = Start Time - Arrival Time):

  • WT(A)=0−0=0\text{WT(A)} = 0 - 0 = 0
  • WT(C)=10−4=6\text{WT(C)} = 10 - 4 = 6
  • WT(B)=13−2=11\text{WT(B)} = 13 - 2 = 11
  • WT(D)=19−6=13\text{WT(D)} = 19 - 6 = 13

Average WT (NP-SJF)=0+6+11+134=304=7.5\text{Average WT (NP-SJF)} = \frac{0 + 6 + 11 + 13}{4} = \frac{30}{4} = 7.5

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore CPU Scheduling questions