Context switches - Example - Operating System

Q.  Three CPU intensive processes requires 10, 20 and 30 time units and arrive at times 0, 2 and 6 respectively. The operating system implements a shortest remaining time first scheduling algorithm. Considering that the context switches at time zero and at the end are not counted the number of context switches are needed is ______.
- Published on 27 Aug 15

a. 4
b. 3
c. 2
d. 1

ANSWER: 2
 

    Discussion

  • Nirja Shah   -Posted on 12 Nov 15
    - Let there be three process P0, P1 and P2 with arrival times 0, 2 and 6 respectively and let their CPU burst times be 10, 20 and 30 respectively.

    - At time 0, P0 is the only available process so it runs.

    - At time 2, P1 arrives, but P0 has the shortest remaining time, so it continues.

    - At time 6, P2 arrives, but P0 has the shortest remaining time, so it continues.

    - At time 10, P1 is scheduled as it is the shortest remaining time process.

    - At time 30, P2 is scheduled. Only two context switches are needed. P0 to P1 and P1 to P2.

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