![]() |
VOOZH | about |
In this article, we discuss Clairvoyant SJF. It is a theoretical concept in which the algorithm looks in the future and waits for the shortest process to arrive, this results in the least average waiting time.
Difference between Clairvoyant SJF and Shortest Job First: Both algorithms work on the same principle of allocating CPU time to the shorter process. The difference lies in the fact that Clairvoyant can look into the future and wait for the shortest process and allocate the resource accordingly, whereas SJF has to allocate the resources to the process which have already arrived (i.e., are waiting for the ready queue).
Examples:
Input: The processes are,
Process id Arrival time Burst time p1 0 5 p2 1 2 p3 3 1 p4 4 3
Output: Process scheduling according to Clairvoyant SJF is,
Process id Arrival time Burst time p3 3 1 p2 1 2 p4 4 3 p1 0 5
The average waiting time is: 2.5
Output: Process scheduling according to Shortest Job First is,
Process id Arrival time Burst time p1 0 5 p3 3 1 p2 1 2 p4 4 3
The average waiting time is : 2.75
Note: Clairvoyant SJF and SJF will give the same result if all the processes arrive at the same time.
Input: The processes are,
Process id Arrival time Burst time p1 0 4 p2 0 9 p3 0 5 p4 0 3
Output: Process scheduling according to Clairvoyant SJF is,
Process id Arrival time Burst time p4 0 3 p1 0 4 p3 0 5 p2 0 9
The average waiting time is : 5.5
Output: Process scheduling according to Shortest Job First is,
Process id Arrival time Burst time p4 0 3 p1 0 4 p3 0 5 p2 0 9
The average waiting time is: 5.5
Code:
Process scheduling according to Clairvoyant SJF is: Process id Arrival time Burst time p3 3 1 p2 1 2 p4 4 3 p1 0 5 The average waiting time is: 2.5