Consider the following set of processes, with the arrival times and th...
The following is Gantt Chart of execution
P1 P2 P4 P3 P1
1 4 5 8 12
Turn Around Time = Completion Time - Arrival Time Avg Turn Around Time = (12 + 3 + 6+ 1)/4 = 5.50
Consider the following set of processes, with the arrival times and th...
Solution:
Preemptive SRPT Algorithm
In the preemptive SRPT algorithm, the process with the shortest remaining time is given priority to execute. If a new process arrives with a shorter burst time than the currently executing process, the CPU is preempted and the new process is scheduled.
Calculation of Turnaround Time
Turnaround time is the total time taken by a process from arrival to completion, including both CPU and waiting time.
Turnaround time = Completion time - Arrival time
Calculation of Completion Time
Completion time is the time at which a process completes its execution.
Completion time = Arrival time + Burst time
Calculation of Waiting Time
Waiting time is the time a process spends waiting in the ready queue before it gets the CPU.
Waiting time = Turnaround time - Burst time
Given Process Details
Process Arrival Time Burst Time
P1 0 5
P2 1 3
P3 2 3
P4 4 1
Step-by-Step Calculation
- At time 0, process P1 arrives and executes. Remaining burst time of P1 is 5.
- At time 1, process P2 arrives with a burst time of 3. P2 is shorter than P1, so P1 is preempted and P2 executes. Remaining burst time of P2 is 2.
- At time 2, process P3 arrives with a burst time of 3. P2 is shorter than P3, so P2 continues to execute. Remaining burst time of P2 is 1.
- At time 3, P2 completes its execution. Completion time of P2 is 3. Turnaround time of P2 is 3 - 1 = 2. Waiting time of P2 is 2.
- At time 4, process P4 arrives with a burst time of 1. P4 is shorter than P3, so P3 is preempted and P4 executes. Remaining burst time of P4 is 0.
- At time 5, P1 resumes execution. Remaining burst time of P1 is 4.
- At time 6, P3 resumes execution. Remaining burst time of P3 is 2.
- At time 7, P3 completes its execution. Completion time of P3 is 7. Turnaround time of P3 is 7 - 2 = 5. Waiting time of P3 is 2.
- At time 8, P1 is preempted by P4. Remaining burst time of P4 is 0.
- At time 9, P1 completes its execution. Completion time of P1 is 9. Turnaround time of P1 is 9 - 0 = 9. Waiting time of P1 is 4.
- At time 10, P4 completes its execution. Completion time of P4 is 10. Turnaround time of P4 is 10 - 4 = 6. Waiting time of P4 is 3.
Calculation of Average Turnaround Time
Average turnaround time is the sum of the turnaround times of all the processes divided by the number of processes.
Average turnaround time = (2 + 5 + 9 + 6) / 4 = 5.5
Therefore, the average turnaround time for these processes with the preemptive SRPT algorithm is 5.