# GATE | GATE-CS-2006 | Question 85

Consider three CPU-intensive processes, which require 10, 20 and 30 time units and arrive at times 0, 2 and 6, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.

**(A)** 1

**(B)** 2

**(C)** 3

**(D)** 4

**Answer:** **(B)** **Explanation:**

Shortest remaining time, also known as shortest remaining time first (SRTF), is a scheduling method that is a pre-emptive version of shortest job next scheduling. In this scheduling algorithm, the process with the smallest amount of time remaining until completion is selected to execute. Since the currently executing process is the one with the shortest amount of time remaining by definition, and since that time should only reduce as execution progresses, processes will always run until they complete or a new process is added that requires a smaller amount of time.

**Solution:**

Let three process be P0, P1 and P2 with arrival times 0, 2 and 6 respectively and CPU burst times 10, 20 and 30 respectively. At time 0, P0 is the only available process so it runs. At time 2, P1 arrives, but P0 has the shortest remaining time, so it continues. At time 6, P2 also arrives, but P0 still has the shortest remaining time, so it continues. At time 10, P1 is scheduled as it is the shortest remaining time process. At time 30, P2 is scheduled. Only two context switches are needed. P0 to P1 and P1 to P2.

See question 1 of https://www.geeksforgeeks.org/operating-systems-set-14/

This solution is contributed by **Nitika Bansal **

Quiz of this Question

## Recommended Posts:

- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 12
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 11
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 10
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 9
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 8
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 7
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 6
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 5
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 4
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 3
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 2
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 1
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 13
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 56
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 55