Redirected
• edited by
24,774 views
61 61 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$

6 Answers

Best answer
80 80 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 6 votes
Only two switches wil be required after process 1 and 2 complete.Option B.
3 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

3 3 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:
Position:
Show:

Related questions

17 17 votes
2 answers 2 answers
10.2k
10.2k views
Rucha Shelke asked Sep 26, 2014
10,178 views
Consider the following code written in a pass-by-reference language like FORTRAN and these statements about the code. subroutine swap(ix,iy) it = ix L1 : ix = iy L2 : iy ...
35 35 votes
4 answers 4 answers
16.6k
16.6k views
gatecse asked Sep 15, 2014
16,552 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 ...
59 59 votes
12 answers 12 answers
25.2k
25.2k views
Rucha Shelke asked Sep 16, 2014
25,219 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...
32 32 votes
3 answers 3 answers
15.6k
15.6k views
gatecse asked Sep 21, 2014
15,554 views
Let $f(x)$ be the continuous probability density function of a random variable $x$, the probability that $a < x \leq b$, is :$f(b-a)$$f(b) - f(a)$$\int\limits_a^b f(x) dx...