# 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 47
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 35
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 34
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 33
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 31
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 30
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 29
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 28
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 27
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 26
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 36
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 37
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 46
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 45
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 44
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 43
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 42
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 41
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 40
- GATE | Sudo GATE 2020 Mock II (10 January 2019) | Question 39