GATE | GATE-CS-2014-(Set-3) | Question 65 - GeeksforGeeks

22 Jul, 2021
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
The average waiting time (in milliseconds) of the processes is _________.(A) 4.5(B) 5.0(C) 5.5(D) 6.5Answer: (C)Explanation:
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. 
Watch GeeksforGeeks video Explanation :
YouTubeGeeksforGeeks GATE Computer Science16.4K subscribersCPU Scheduling GATE Previous Year Questions Part-II with Viomesh SinghWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:0020:07 / 49:57•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=maVQoJuMAlM" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>Quiz of this Question
GATE-CS-2014-(Set-3)
GATE-GATE-CS-2014-(Set-3)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | Gate IT 2007 | Question 25
GATE | GATE-CS-2001 | Question 39
GATE | GATE-CS-2000 | Question 41
GATE | GATE-CS-2005 | Question 6
GATE | GATE MOCK 2017 | Question 21
GATE | GATE MOCK 2017 | Question 24
GATE | GATE-CS-2006 | Question 47
GATE | Gate IT 2008 | Question 43
GATE | GATE-CS-2009 | Question 38
GATE | GATE-CS-2003 | Question 90