📜  门| GATE-CS-2005 |问题 4(1)

📅  最后修改于: 2023-12-03 14:58:26.855000             🧑  作者: Mango

GATE-CS-2005 Problem 4

This is a problem from the GATE (Graduate Aptitude Test in Engineering) Computer Science and Information Technology exam in 2005.

Problem Statement

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:

  1. P2 will complete before P1.
  2. P1 will complete before P4.
  3. P5 will complete before P3.

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

Solution

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.

Completion Time Calculation

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:

  • P1: 13ms
  • P2: 1ms
  • P3: 8ms
  • P4: 2ms
  • P5: 13ms
Checking the Statements

Statement 1

P2 has the shortest burst time of all the processes, so it should complete before any other process. This statement is TRUE.

Statement 2

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.

Statement 3

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.

Conclusion

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.