Lab 5
Lab 5
Description: Implementing shortest job first and shortest remaining time first algorithm to
visualize how a cpu processes the process
Shortest Job First (SJF) is an algorithm in which the process having the smallest execution
time is chosen for the next execution. This scheduling method is preemptive .It significantly
reduces the average waiting time for other processes awaiting execution.
Algorithm:
1. Take the number of process , burst time and arrival time for each process as input.
2. We initialize the count and completion time to keep record of completed process and
completion time of process.
3. Scheduling (SJF):
While not all processes are completed (count < n):
● Find the process with the shortest burst time among those that have arrived.
● Update completiontime by adding the burst time of the selected process.
● Mark the process as completed and calculate its completion time (ct), turnaround time
(tat), and waiting time (wt).
● Set the burst time of the completed process to 0.
● Increment the count.
4. Calculate the total turnaround time and total waiting time.
5. Display the average turnaround time and waiting time by dividing it by total number of process.
.Code:
Output:
Code:
Output:
Conclusion:
In this lab we learned and implemented shortest job first and shortest time remaining first
algorithm for cpu scheduling to the process and we saw how it is much more efficient from
FCFS algorithm.