in Operating System
1,675 views
1 vote
1 vote
Consider arrival time and execution time for the following process:-

P.id    A.T     B.T

1        2         5

2        7         9

3        8         3

4       10        4

 Assume, each context switch requires 1ms time (excluding first and last context switch).then solve it using SRTF(shortest remaining time first)
in Operating System
1.7k views

4 Comments

@Syntax-error

Then I think the answer given is wrong because they’re not considering the Context switch which will occur at time t= 8 when P3 comes in ready queue .

Where have you taken this question from?

1
1
it seems , it is done by SJF,  not SRTF in the given image. + I have doubt that at 7 ms we will have context switch till 8 ms but at 8 ms P3 will also come in ready queue so we will do context switch for scheduling P3 now because it has less burst time. What I am missing ? or P2 will run for 1 ms till switching being done for executing P3??
0
0

@chinmay_rajpurohit

You’re right , At Time t=8 there will be another context switch and P2 won’t be able to run even for 1ms.

1
1

1 Answer

2 votes
2 votes
At time t=2 , Process 1 arrives (Since no time required for Context Switch) , it starts execution and completes execution at Time t = 7.

At time t=7 , Process 2 comes in and due to Context switch it takes 1ms to get into the Running state but at Time t= 8 , Process 3 comes in with less Burst time  so now there is Context switch before P2 starts executing(P2 couldn’t even execute for 1ms)  and Process 3 enters CPU at Time t = 9  (8 + 1 where 8 is Arrival Time and 1ms for Context switch)

At time t = 9 , Process 3 starts executing till time t= 10 when Process 4 arrives with Burst time 4ms. But since remaining Burst time of Process 3 (2ms) < Burst time of Process 4 < Burst time of Process 2 , there is no context switch and Process 3 continues execution .

At time t = 12 , Process 3 completes execution and there is Context switch , So Process 4 starts execution at time t = 13 .

At time t = 17 , Process 4 completes execution and there is a context switch . So Process 2 starts execution at time t = 18ms.

At time t = 27ms , Process 4 completes execution and since no time taken for Context switch for last process the Completion time is t = 27ms.

Related questions