13,270 views

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$

option c
edited

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$)

by

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)

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

So only 2
But after termination of the process ,PCB of that process gets deleted.
Only two switches wil be required after process 1 and 2 complete.Option B.
by

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

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

@Headshot I also had this doubt while solving but none of the options matched :/
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.