P4 with lower Burst time arrived when P3 was executing so why P3 didn't got preempted?

According to me: P1,P2,P3,P4,P3,P1 should be the schedule.

and Avg. Waiting time is coming as 5.75ms.

Please correct me if I am wrong...

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+12 votes

An operating system uses *shortest remaining time first* scheduling algorithm for pre-emptive scheduling of processes. Consider the following set of processes with their arrival times and CPU burst times (in milliseconds):

Process | Arrival Time | Burst Time |
---|---|---|

$P1$ | $0$ | $12$ |

$P2$ | $2$ | $4$ |

$P3$ | $3$ | $6$ |

$P4$ | $8$ | $5$ |

$$\begin{array}{|l|l|l|} \hline \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time}\\\hline \text{P1} & 0 & 12 \\\hline \text{P2} & 2 & 4 \\\hline \text{P3} & 3 & 6 \\\hline \text{P4} & 8 & 5 \\\hline \end{array}$$

The average waiting time (in milliseconds) of the processes is ______.

+17 votes

Best answer

Arrival Time | Burst Time | Completion Time | Turn Around Time | Waiting Time $= CT - BT - AT$ | |

$p1$ | $0$ | $12$ | $27$ | $27$ | $15$ |

$p2$ | $2$ | $4$ | $6$ | $4$ | $0$ |

$p3$ | $3$ | $6$ | $12$ | $9$ | $3$ |

$p4$ | $8$ | $5$ | $17$ | $9$ | $4$ |

$$\begin{array}{|l|l|l|l|l|l|} \hline \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time} & \textbf{Completion Time} & \textbf{Turn Around Time} & \textbf{Waiting Time = CT - BT -AT} \\\hline \text{P1} & 0 & 12 & 27 & 27 & 15 \\\hline \text{P2} & 2 & 4 & 6 & 4 & 0 \\\hline \text{P3} & 3 & 6 & 12 & 9 & 3 \\\hline \text{P4} & 8 & 5 & 17 & 9 & 4 \\\hline \end{array}$$

$(15 + 0 + 3 + 4)/4 = 5.5$ msecs

$p1 \ p2 \ p2 \ p3 \ p3 \ p4 \ p1$

$0 \ 2 \ 3 \ 6 \ 8 \ 12 \ 17 \ 27$

0

Why P3 not got preempted at 8ms?

P4 with lower Burst time arrived when P3 was executing so why P3 didn't got preempted?

According to me: P1,P2,P3,P4,P3,P1 should be the schedule.

and Avg. Waiting time is coming as 5.75ms.

Please correct me if I am wrong...

P4 with lower Burst time arrived when P3 was executing so why P3 didn't got preempted?

According to me: P1,P2,P3,P4,P3,P1 should be the schedule.

and Avg. Waiting time is coming as 5.75ms.

Please correct me if I am wrong...

+1

@ hsd31196

When P4 arrived, remaining burst time of P3 was 4 while burst time of P4 was 5. So P3 continued to execute

0 votes

Process Arrival Time Burst Time P1 0 12 P2 2 4 P3 3 6 P4 8 5

Burst Time - The total time needed by a process from the CPU for its complete execution. Waiting Time - How much time processes spend in the ready queue waiting their turn to get on the CPU Now, The Gantt chart for the above processes is :

P1 - 0 to 2 milliseconds P2 - 2 to 6 milliseconds P3 - 6 to 12 milliseconds P4 - 12 to 17 milliseconds P1 - 17 to 27 milliseconds

Process p1 arrived at time 0, hence cpu started executing it. After 2 units of time P2 arrives and burst time of P2 was 4 units, and the remaining time of the process p1 was 10 units,hence cpu started executing P2, putting P1 in waiting state(Pre-emptive and Shortest remaining time first scheduling). Due to P1's highest remaining time it was executed by the cpu in the end.

Now calculating the waiting time of each process: P1 -> 17 -2 = 15 P2 -> 0 P3 -> 6 - 3 = 3 P4 -> 12 - 8 = 4 Hence total waiting time of all the processes is = 15+0+3+4=22 Total no of processes = 4 Average waiting time = 22 / 4 = 5.5 Hence C is the answer.

- All categories
- General Aptitude 1.6k
- Engineering Mathematics 7.5k
- Digital Logic 3k
- Programming & DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6k
- Compiler Design 2.1k
- Databases 4.2k
- CO & Architecture 3.5k
- Computer Networks 4.2k
- Non GATE 1.4k
- Others 1.5k
- Admissions 585
- Exam Queries 572
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

50,126 questions

53,252 answers

184,759 comments

70,502 users