# 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 41
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 54
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 55
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 56
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 57
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 58
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 59
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 60
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 61
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 62
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 53
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 52
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 51
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 42
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 43