Preemptive Shortest Job First (SJF) scheduling algorithm - Example - Operating System

Q.  We have three processes P0, P1 and P2 whose arrival time and burst time are given below.
If the preemptive Shortest Job First (SJF) scheduling algorithm is carried out only at arrival or   completion of processes then the average waiting time for the three processes is ________.

- Published on 26 Aug 15
computer-science-23.png


a. 7.33ms
b. 6.33ms
c. 5.0ms
d. 4.33ms

ANSWER: 5.0ms
 

    Discussion

  • Nirja Shah   -Posted on 21 Nov 15
    - Process P0 is allocated processor at 0 ms as there is no other process in ready queue.

    - P0 is preempted after 1 ms as P1 arrives at 1 ms and burst time for P1 is less than remaining time of P0. P1 runs for 4ms.

    - P2 arrived at 2 ms but P1 continued as burst time of P2 is longer than P1.

    - After P1 completes, P0 is scheduled again as the remaining time for P0 is less than the burst time of P2.

    - P0 waits for 4 ms, P1 waits for 0 ms and P2 waits for 11 ms. So average waiting time is (0+4+11)/3 = 5.

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)