GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Simulate SRTF and derive waiting or turnaround time

8 questions solved the same way, newest first. Back to Operating Systems

How these are solved

Each question supplies process arrival times and one CPU burst per process, requires simulating preemptive shortest remaining time first (called SRPT in 2004), and derives an average from process completion times.

1 mark · MCQ
Report issue

CPU Scheduling

Question 26, GATE 2025: Processes P1,P2,P3,P4 arrive at times 0,1,2,8 ms and require 10,13,6,9 ms of CPU time respectively. Scheduling uses preemptive Shortest Remaining Time First with no context-switch cost. Find average turnaround time.
Options: A. 22 ms; B. 15 ms; C. 37 ms; D. 19 ms.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Step through it (7 steps)

Track remaining time at each arrival rather than comparing original burst times throughout. At t=0 only P1 is available. At t=1 P1 has 9 ms left, less than P2's 13, so P1 continues. At t=2 P1 has 8 ms left and P3 arrives needing 6; P3 preempts it and runs from 2 to 8.

At t=8 P3 completes and P4 arrives. Remaining times are P1:8, P2:13, P4:9, so choose P1 for 8…16. Next choose P4 for 16…25, followed by P2 for 25…38. The execution intervals are therefore P1 [0,2), P3 [2,8), P1 [8,16), P4 [16,25), P2 [25,38).

Turnaround equals completion minus arrival: P1=16−0=16, P2=38−1=37, P3=8−2=6, P4=25−8=17 ms. Their sum is 76 ms and the average is 76/4=19 ms. Waiting time would subtract each burst as well; that is not the requested metric. Answer: D.

Original paper, page 21 · Answer key

2 marks · MCQ
Report issue

Compare preemptive and nonpreemptive shortest-job schedules

CPU Scheduling

Question 37, GATE 2024: Four processes have (arrival,burst): A(0,10), B(2,6), C(4,3), D(6,7). Find average waiting times for SRTF and nonpreemptive SJF. A 6,7; B 6,7.5; C 7,7.5; D 7,8.5.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Step through it (2 schedules)

Approach: Draw a separate timeline for each policy, then use waiting=completion−arrival−burst.

1. Derivation. SRTF runs A0–2, B2–4, C4–7, B7–11, D11–18, A18–26. Completion times A26, B11, C7, D18 give waiting times 16, 3, 0, 5 after subtracting arrival and burst, average 24/4=6. Nonpreemptive SJF runs A0–10, C10–13, B13–19, D19–26, giving waiting times 0, 11, 6, 13 and average 30/4=7.5. Answer B. D’s arrival at 6 does not preempt C, whose remaining time is 1.

2. Explanation and checks. For SRTF, at time 2 A has 8 left and B needs 6, so B preempts A. At time 4 B has 4 left and C needs 3, so C preempts B. At time 6 C needs only 1 more, so D does not preempt it. In nonpreemptive SJF, A cannot be displaced after starting at time 0; when it finishes at 10 all others are ready and C is shortest. These decisions explain the difference in the two timelines.

Original paper, page 25 · Answer key

1 mark · NAT
Report issue

CPU Scheduling

Question 24, GATE 2017: Processes P1,P2,P3,P4 have (arrival,CPU burst) in ms: (0,7),(3,3),(5,5),(6,2). Use preemptive shortest-remaining-time-first scheduling and find average waiting time.
Tap to enlarge
Answer & solution

Official answer: 3.0

Our answer: 3

Step through it (7 steps)

1. Run P1 at t=0. At t=3 it has 4 ms left, so newly arrived P2 with 3 ms preempts it. At t=5 P2 has only 1 ms left, less than P3’s 5, so P2 continues to completion at 6.

2. At t=6 choose P4’s 2 ms over P1’s 4 and P3’s 5. P4 completes at 8, P1 runs 8–12, then P3 runs 12–17.

3. Waiting=completion−arrival−burst. For P1,P2,P3,P4 these are 12−0−7=5,6−3−3=0,17−5−5=7,8−6−2=0. Average=(5+0+7+0)/4=3 ms.

Original paper, page 12 · Answer key

2 marks · NAT
Report issue

CPU Scheduling

Question 47, GATE 2016: Preemptive shortest-remaining-time-first schedules P1(arrival 0,burst 10), P2(3,6), P3(7,1), P4(8,3), all times ms. Find average turnaround time.
Tap to enlarge
Answer & solution

Official answer: 8.2 : 8.3

Our answer: 8.25

Step through it (7 steps)

SRTF executes P1: 0–3, P2: 3–7, P3: 7–8, P2: 8–10, P4: 10–13, P1: 13–20. Turnaround times are 20−0=20, 10−3=7, 8−7=1, 13−8=5. Average33/4=8.25ms, within the official 8.2–8.3 interval.

At time 3, P1 has 7 ms left, so arriving P2 with 6 preempts it. At time 7, P2 has 2 left, so P3 with 1 preempts. At time 8, P2’s remaining 2 beats P4’s 3 and P1’s 7. Turnaround includes all waiting after arrival; average waiting would instead subtract each burst and yield 3.25 ms.

Original paper, page 39 · Answer key

2 marks · NAT
Report issue

CPU Scheduling

Question 32, GATE 2014: Five processes have (arrival time, execution time), in ms: A=(0,6), B=(3,2), C=(5,4), D=(7,6), E=(10,3). Under preemptive shortest-remaining-time-first on one CPU, find the average turnaround time in ms.
Tap to enlarge
Answer & solution

Official answer: 7.2

Step through it (9 steps)

1. Method and setup. Reevaluate the currently running process whenever a new process arrives. Compare remaining execution time, not the original burst length. Record completion time for each process, then subtract its own arrival time; averaging completion times directly would ignore that the processes enter at different times.

2. Work through the result and its assumptions. SRTF executes A0–3, B3–5, A5–8, C8–12, E12–15, D15–21. At10, C has 2 remaining versus E’s3, so it continues. Completion-minus-arrival times are 8, 2, 7, 14, 5. Their mean 36/5=7.2ms.

Original paper, page 15 · Answer key

2 marks · NAT
Report issue

CPU Scheduling

Question 32, GATE 2014: Preemptive shortest-remaining-time-first scheduling is applied to processes (arrival,CPU burst), in ms: P1=(0,12), P2=(2,4), P3=(3,6), P4=(8,5). Find their average waiting time.
Tap to enlarge
Answer & solution

Official answer: 5.5

Step through it (8 steps)

Step 1: P1 runs 0–2, leaving 10. P2 arrives with burst 4 and preempts it. At time 3, P2 has 3 remaining, shorter than P3's 6, so P2 finishes at 6. Step 2: P3 then runs 6–12. When P4 arrives at 8, P3 has 4 remaining, less than P4's 5, so no preemption occurs. P4 runs 12–17, then P1 runs 17–27. Step 3: Waiting time equals completion−arrival−burst: P1=27−0−12=15; P2=6−2−4=0; P3=12−3−6=3; P4=17−8−5=4. The average is (15+0+3+4)/4=5.5 ms, assuming negligible switching cost.

Original paper, page 60 · Answer key

2 marks · MCQ
Report issue

Preemptive shortest-remaining-time schedule

CPU Scheduling

Question 35, GATE 2011: Processes P0,P1,P2 have (arrival,burst) times in ms of (0,9),(1,4),(2,9). Use preemptive shortest-job-first scheduling, reconsidering at arrivals or completions. What is their average waiting time?

(A) 5.0 ms
(B) 4.33 ms
(C) 6.33 ms
(D) 7.33 ms
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Step through it (6 steps)

P0 runs 0–1, then P1 with its shorter remaining time runs 1–5 despite P2 arriving at 2. P0 finishes its remaining 8 units during 5–13; P2 then runs 13–22. Waiting times are 13−0−9=4, 5−1−4=0 and 22−2−9=11. Average(4+0+11)/3=5ms, A.

At time 1, P0 has 8 units remaining and P1 needs 4, so preemption is required. At time 2, P1 has only 3 remaining, less than P0's 8 and newly arrived P2's 9, so no further preemption occurs. Waiting time is turnaround minus burst, not completion time alone. P0 waits from 1 to 5, P1 never waits, and P2 waits from 2 to 13. These intervals independently reproduce the total 15 ms waiting time.

Original paper, page 9 · Answer key

2 marks · MCQ
Report issue

Preemptive shortest remaining time

CPU Scheduling

Question 46, GATE 2004: Processes (arrival time,CPU burst), in ms, are P1=(0,5), P2=(1,3), P3=(2,3), P4=(4,1). What is the average turnaround time under preemptive shortest remaining processing time first (SRPT)?
Options:
(A) 5.50 ms
(B) 5.75 ms
(C) 6.00 ms
(D) 6.25 ms
Question 46, GATE 2004: Processes (arrival time,CPU burst), in ms, are P1=(0,5), P2=(1,3), P3=(2,3), P4=(4,1). What is the average turnaround time under preemptive shortest remaining processing time first (SRPT)?
Options:
(A) 5.50 ms
(B) 5.75 ms
(C) 6.00 ms
(D) 6.25 ms
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step through it (7 steps)

1. A valid SRPT schedule is P1:[0,1), P2:[1,4), P4:[4,5), P3:[5,8), P1:[8,12). P2 still has the smallest remaining time when P3 arrives.

2. Completion times for P1,P2,P3,P4 are 12,4,8,5; subtracting arrivals 0,1,2,4 gives turnaround times 12,3,6,1. Their mean is 22/4=5.50ms.

3. Teaching check: Turnaround is completion minus arrival, not total waiting time. The four turnaround values are 12,3,6,1; their sum is 22. Context-switch overhead is not supplied and is therefore excluded. Arrival of P3 at time 2 does not preempt P2, whose remaining burst is only 2.

Original paper, page 6