in Operating System edited by
13,270 views
35 votes
35 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$
in Operating System edited by
13.3k views

3 Comments

option c
0
0
0
0
edited by
0
0

4 Answers

59 votes
59 votes
Best answer

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 \ \ p1$ is preempted and check that available process have shortest job time or not, but he did not get anyone 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
by

4 Comments

Bro, you are counting one context switch as twice (you divided context switch process in two half and you are counting each half as one context switch, it is not fair)

0
0
Meghna, that is why initial and last CS is ignored.

So only 2
0
0
But after termination of the process ,PCB of that process gets deleted.
0
0
6 votes
6 votes
Only two switches wil be required after process 1 and 2 complete.Option B.
by
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

3 votes
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

2 Comments

@Headshot I also had this doubt while solving but none of the options matched :/
2
2
Say if round robin would be used here with time slice equals to 1 , then those switches will be considered as context switches, right?

Because here we are saving the burst time of a particular job in it’s PCB and restoring it after processor processes the same job again. So, here context switches would occur according to what I have understood. Please correct me if I am wrong.
0
0
Answer:

Related questions