You are on page 1of 5

 First-Come First-Serve Scheduling, FCFS

 Every single waiting time must be calculated.


 Then calculate the Total Waiting Time and the Average Waiting Time of the FCFS
algorithm.
 FCFS is very simple - Just a FIFO queue, like customers waiting in line at the
bank or the post office or at a copying machine.
 Unfortunately, however, FCFS can yield some very long average wait times,
particularly if the first process to get there takes a long time.

For example, consider the following three processes:

Process Burst Time


P1 24
P2 3
P3 3

 In the first Gantt chart below, process P1 arrives first. The average
waiting time for the three processes is ( 0 + 24 + 27 ) / 3 = 17.0 ms.
 In the second Gantt chart below, the same three processes have an
average wait time of ( 0 + 3 + 6 ) / 3 = 3.0 ms. The total run time for the
three bursts is the same, but in the second case two of the three finish
much quicker, and the other process is only delayed by a short amount.

 FCFS can also block the system in a busy dynamic system in another
way, known as the convoy effect. When one CPU intensive process
blocks the CPU, a number of I/O intensive processes can get backed up
behind it, leaving the I/O devices idle. When the CPU hog finally
relinquishes the CPU, then the I/O processes pass through the CPU
quickly, leaving the CPU idle while everyone queues up for I/O, and
then the cycle repeats itself when the CPU intensive process gets back to
the ready queue.

 Shortest-Job-First Scheduling, SJF

 It is FCFS concept, but the process which comes at the same time or the same ready queue
must be sorted in ascending order. The smallest burst time will be the first order while the
bigger will be the last one.
 The idea behind the SJF algorithm is to pick the quickest fastest little job that
needs to be done, get it out of the way first, and then pick the next smallest fastest
job to do next.( Technically this algorithm picks a process based on the next
shortest CPU burst, not the overall process time. )

For example, the Gantt chart below is based upon the following CPU burst
times, ( and the assumption that all jobs arrive at the same time. )

Process Burst Time


P1 6
P2 8
P3 7
P4 3

 In the case above the average wait time is ( 0 + 3 + 9 + 16 ) / 4 = 7.0 ms,


( as opposed to 10.25 ms for FCFS for the same processes. )
 SJF can be proven to be the fastest scheduling algorithm, but it suffers
from one important problem: How do you know how long the next CPU
burst is going to be?
o For long-term batch jobs this can be done based upon the limits
that users set for their jobs when they submit them, which
encourages them to set low limits, but risks their having to re-
submit the job if they set the limit too low. However that does not
work for short-term CPU scheduling on an interactive system.

 Another option would be to statistically measure the run time characteristics of


jobs, particularly if the same tasks are run repeatedly and predictably. But once
again that really isn't a viable option for short term CPU scheduling in the real
world.
 A more practical approach is to predict the length of the next burst, based on some
historical measurement of recent burst times for this process. One simple, fast, and
relatively accurate method is the exponential average, which can be defined as
follows. ( The book uses tau and t for their variables, but those are hard to
distinguish from one another and don't work well in HTML. )

estimate[ i + 1 ] = alpha * burst[ i ] + ( 1.0 - alpha ) * estimate[ i ]

 Round Robin Scheduling

 The calculation in Round Robin is more difficult than the earlier calculations. In this
algorithm, it needs to split the best time into several subprocesses in a period.
 Quantum Time is a time slicing technique to split burst time into several subprocesses.
Testing the same data with different quantum times is giving the different AWT.
 When a process is given the CPU, a timer is set for whatever value has been set
for a time quantum.

o If the process finishes its burst before the time quantum timer
expires, then it is swapped out of the CPU just like the normal
FCFS algorithm.
o If the timer goes off first, then the process is swapped out of the
CPU and moved to the back end of the ready queue.

 The ready queue is maintained as a circular queue, so when all processes have had
a turn, then the scheduler gives the first process another turn, and so on.
 RR scheduling can give the effect of all processors sharing the CPU equally,
although the average wait time can be longer than with other scheduling
algorithms.

In the following example the average wait time is 5.66 ms.

Process Burst Time


P1 24
P2 3
P3 3
 The performance of RR is sensitive to the time quantum selected. If the
quantum is large enough, then RR reduces to the FCFS algorithm; If it is
very small, then each process gets 1/nth of the processor time and share
the CPU equally.
 BUT, a real system invokes overhead for every context switch, and the
smaller the time quantum the more context switches there are. ( See
Figure 5.4 below. ) Most modern systems use time quantum between 10
and 100 milliseconds, and context switch times on the order of 10
microseconds, so the overhead is small relative to the time quantum.

 In general, turnaround time is minimized if most processes finish their next cpu
burst within one time quantum. For example, with three processes of 10 ms bursts
each, the average turnaround time for 1 ms quantum is 29, and for 10 ms quantum
it reduces to 20. However, if it is made too large, then RR just degenerates to
FCFS. A rule of thumb is that 80% of CPU bursts should be smaller than the time
quantum.

You might also like