edited by
15,786 views
39 votes
39 votes

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.

  1. $1$
  2. $2$
  3. $3$
  4. $4$
edited by

4 Answers

Best answer
65 votes
65 votes

Processes execute as per the following Gantt chart 

So, here only $2$ switching possible (when we did not consider the starting and ending switching )

Now here might be confusion that at $t= 2 \;\;p_{1}$ is preempted and scheduler checks that the newly arrived process has shorter job time or not, and does not find one, so it should not be consider as context switching (same happened at $t=6$).

Reference: http://stackoverflow.com/questions/8997616/does-a-context-switch-occur-in-a-system-whose-ready-queue-has-only-one-process-a (thanks to anurag_s)

Answer is (B)

edited by
6 votes
6 votes
Only two switches wil be required after process 1 and 2 complete.Option B.
3 votes
3 votes

Since SRTF is used, processess execute in order:switching to P1 included(given in question)P1-- 10 units; then switch to P2 -- 20 units; then switch to P3 -- 30 units. (Here arrival time need not be considered)

Total context switch= 3

2 votes
2 votes

0

when execution of one process is completed and other process is scheduled , Is it called Context switch ?

I think , It is not Context switch, as according to wiki

In computing, a context switch is the process of storing the state of a process or of a thread, so that it can be restored and execution resumed from the same point later. This allows multiple processes to share a single CPU, and is an essential feature of a multitasking operating system.

As we are not storing results od earlier process for later execution. If there are any results produced by some operation within process or program , It is responsibility of program (or process when it running) to store them back.

For example : when C program to add two number gets converted to Assembly language code , It also has instruction to store result of addition back into memory.

Hence answer to this previous year gate question must be 0

Answer:

Related questions

30 votes
30 votes
3 answers
2
gatecse asked Sep 15, 2014
11,298 views
Consider the polynomial $p(x) = a_0 + a_1x + a_2x^2 + a_3x^3$ , where $a_i \neq 0$, $\forall i$. The minimum number of multiplications needed to evaluate $p$ on an input ...
41 votes
41 votes
11 answers
3
Rucha Shelke asked Sep 16, 2014
15,903 views
A CPU has $24$-$bit$ instructions. A program starts at address $300$ (in decimal). Which one of the following is a legal program counter (all values in decimal)?$400$$500...