SJF
SJF
net/publication/234556241
CITATIONS READS
8 2,985
2 authors:
Some of the authors of this publication are also working on these related projects:
Information Security Mechanism for Real Wireless Mesh Network Scenario (E-healthcare) View project
All content following this page was uploaded by Basit Shahzad on 31 January 2017.
1.2 SJF 0 3 11 20 35 55
Figure No. 2: Execution of processes in
On the other hand Shortest Job First selects SJF.
the process with shortest time of execution
and executes the process. For SJF the average waiting time is
(3+11+20+35)/5= 69/5=13.8ms which is the
When the CPU is available, the process with minimum average waiting time.
the shortest CPU burst is selected. If two or
more processes have the same CPU burst 1.3 Enhanced SJF algorithm
time, then the FCFS algorithm is used to
determine a tie. In Enhanced SJF, Shorter processes are
SJF is provably optimal. By moving shorter assigned the CPU as in SJF but this
processes to the front of the waiting queue, algorithm makes sure that after some
reduces the average waiting time up to interval bigger processes can get the CPU.
The interval is selected dynamically.
maximum extent.
In fact processes are sorted as soon as they
Major drawback of SJF is that shorter arrive in the ready queue based upon their
processes arrive in ready queue constantly execution time. Shorter processes are
and bigger processes continue growing arranged at the front of queue and bigger
towards tail of ready queues and their processes at the rear of the queue. Two
chance of getting CPU time even decreases. pointers are used, one at the front of the
SJF algorithm may cause a Process to block queue and second at the rear of the queue,
for indefinite time. which is used to pick a process either from
front or from rear of the queue.
When the IBM 7094 at MIT was shut down
in 1973, found that low priority Processes Then a process is picked from front of queue
were found that were submitted in 1967 and that is shortest process and its estimated
were still pending and had not yet been run time is saved in a variable ‘VarShorterJobs’
[1].Same the case may be with SJF if shorter and the estimated time of the biggest
processes arrive on regular basis and bigger processes is saved in variable ‘VarLargeJob’
processes will be waiting to get the chance then next process is picked from front and
and will not execute for a long time and may its estimated time is added to the variable
starve. ‘VarShorterJobs’ and compared it with the
variable ‘VarLargeJob’ when
But Enhanced SJF algorithm ensures that ‘VarShortJobs’ is equal to or greater than
bigger Processes will not starve and they the ‘VarLargeJob’ then a process is picked
will get the CPU after some specific time. from the rear and ‘VarShorterJobs’ is set to
zero and set the ‘VarLargeJob’ to the next now the value of ‘VarShorterJobs’ becomes
bigger process in the queue. In this way after 11. Again after execution of process P4.
equal time of execution of shorter processes Process P5 is selected from the front of the
a bigger process will also get the CPU and queue and value of variable
again return the control to the shorter ‘VarShorterJobs’ becomes 20. after the
processes to be picked next for execution. execution of P5. When the values of
variables are compared to pick the next
In this way bigger processes will not starve process then value of ‘VarShorterJob’
as may be in SJF and average waiting time becomes equal to value of the
for Enhanced SJF will also be approaching ‘VarLargeJob’. Now the bigger process will
to average waiting time of the SJF in many be given the chance for execution. After the
cases. Some solutions might be added by execution of P2, process P1 is selected for
introducing the time slices for each process. execution.
In that case additional computation is
required for context switches. By giving The difference between SJF and Enhanced
CPU to bigger processes without introducing SJF is that SJF will serve the process P1
the time slice, gives strength to the then the process P2 because process P1 has
Enhanced SJF algorithm for consideration. shorter CPU Burst time than process P2, but
Enhanced SJF execute Process P2 first
The Enhanced SJF for the same set of because the sum of the estimated time for
Processes which was discussed in FCFS and execution for shorter processes is greater
in SJF. than or equal to the estimated time for bigger
process which is waiting. So, Enhanced SJF
Processes CPU Burst Waiting Time gives an equal chance of execution to bigger
P1 15 40 processes as well. Figure No.4 shows the
P2 20 20 details.
P3 3 0
P4 8 3
P5 9 11 P3 P4 P5 P2 P1
References
[5]http://williamstallings.com/Extras/OS-
Notes/h6.html
[6]http://www.sci.brooklyn.cuny.edu/~philar
is/cis25/cpusched.html