SJF (Shortest Job First Scheduling)



Objective:
·         To implement ‘Shortest Job First’ CPU scheduling algorithm.
Theory:
Shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process with the smallest execution time to execute next. SJN is a non-preemptive algorithm.
Example:
Process
Burst Time
P1
6
P2
8
P3
7
P4
3
The Gantt chart for the schedule is:
Waiting time for P1=3, P2=16, P3=9, P4=0. Average waiting time=(3+16+9+0)/4=7
Algorithm:
1.     Start the program and get the number of processes p[i] and their burst time bt_p[i].
2.     Initialize the waiting time for process 1, wt_p[1] with 0.
3.     Sort all the processes in increasing order according to burst time.
4.     Process for(i=1;i<=n;i++) => wt_p[i]=wt_p[i-1]+bt_p[i-1].
5.     The waiting time of all the processes is summed then average wait time is calculated.
6.     The waiting time of each process and average times are displayed.
7.     Stop the program.

Task:
Write a C++ code to implement CPU scheduling algorithm Shortest Job First(SJF).

Post a Comment

0 Comments