Professional Documents
Culture Documents
SJFS
SJFS
“NON-
PREEMPTIVE”
This algorithm associates with each
process the length of the process’s
next CPU burst. When the CPU is
available, it is assigned to the process
that has the smallest next CPU burst.
If the next CPU bursts of two
processes are the same, FCFS
scheduling is used to break the tie.
a) When the arrival time of all processes is ‘0’
(all processes arrive at same time)
P1 0 6
P2 0 25
P3 0 9
P4 0 4
--> Since the arrival time of all processes is same, we’ll sort the processes
according to the burst time; shortest executing first.
Gantt Chart
P4 P1 P3 P2
0 4 10 19 44
Gantt Chart
P4 P1 P3 P2
0 4 10 19 44
P1 0 6
P2 1 25
P3 2 9
P4 3 4
--> Since all the processes are already sorted w.r.t arrival time, we’ll sort
the processes according to the burst time; shortest executing first. So, ‘P4’
must have been selected, but at time ‘0’, P4 hasn’t entered the system. So
initially ‘P1’ will have to execute till time ‘6’ and by that time all the
processes have arrived, so next ‘P4’ will be selected and so on.
Gantt Chart
P1 P4 P3 P2
0 6 10 19 44
P1 0 8
P2 1 25
P3 2 9
P4 3 4
Since P2 & P3 arrived but have more burst time than P1’s
remaining Burst time, P1 continues till time unit ‘3’ when P4 arrives.
PID Arrival Time Burst Time
P1 0 8
P2 1 25
P3 2 9
P4 3 4
0 3 7 12 21 46
(for P1, it arrived and started execution at time 0 till 3 time units. But,
it also waited for 4 time units when it got preempted (as P4 as
executing during that time), and started again at time 7, So total
waiting time will be:
Starting time – arrival time + Time waited again = 0 – 0 + 4
= 4 units )
Turnaround Time = 4 + 8 = 12
P1 P4 P1 P3 P2
0 3 7 12 21 46
---------------------------------------------------------------------------------------------
Average Waiting time : (4 + 20 + 10 + 0) / 4 = 34 / 4 = 8.5
The End