📅  最后修改于: 2023-12-03 14:58:26.855000             🧑  作者: Mango
This is a problem from the GATE (Graduate Aptitude Test in Engineering) Computer Science and Information Technology exam in 2005.
Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:
Process | Burst Time (in ms) ------- | ----------------- P1 | 10 P2 | 1 P3 | 2 P4 | 1 P5 | 5
The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0. The scheduler implements the preemptive shortest job first scheduling algorithm. If two processes have the same length of CPU-burst time, then they are scheduled in the order of their arrival.
Consider the following statements:
Which of the above statements are TRUE?
(A) 1 and 2 only (B) 2 and 3 only (C) 1 and 3 only (D) 1, 2, and, 3
To apply the preemptive shortest job first scheduling algorithm, we need to know the burst time of each process and also the arrival time to break the ties. Let's calculate the completion time of each process and check the given statements.
We can use a Gantt chart to visualize the execution of processes. Here is the Gantt chart for the given set of processes:
| Process | P2 | P4 | P3 | P5 | P1 | | ------- | --- | --- | --- | --- | --- | | Time | 0 | 1 | 3 | 8 | 13 |
From the above table, we can see that the completion times of the processes are:
P2 has the shortest burst time of all the processes, so it should complete before any other process. This statement is TRUE.
P1 has the largest burst time among all the processes, but it arrives first. P4, on the other hand, has a smaller burst time but arrives later. So, P1 should complete before P4. This statement is TRUE.
P3 has a smaller burst time than P5 but arrives later. P5, on the other hand, has a larger burst time but arrives first. So, P5 should complete before P3. This statement is FALSE.
Hence, the correct option is (A) 1 and 2 only.
In this problem, we have looked at the application of the preemptive shortest job first scheduling algorithm. We have calculated the completion time of each process and checked the given statements. The problem demonstrates the importance of considering the arrival time of processes in scheduling algorithms.