Friday 20 March 2015

Algorithms:Round Robin scheduling Algorithm

Concept:Round-robin (RR) is one of the algorithms employed by process and network schedulers in computing.As the term is generally used, time slices are assigned to each process in equal portions and in circular order, handling all processes without priority (also known as cyclic executive). Round-robin scheduling is simpleeasy to implement, and starvation-free. Round-robin scheduling can also be applied to other scheduling problems, such as data packet scheduling in computer networks. It is an Operating System concept.

Pseudo Code : 
* CPU scheduler picks the process from the circular/ready queue , set a timer to interrupt it after 1 time slice    / quantum  and dispatches it .
*  If  process has burst time less than 1 time slice/quantum             
             >  Process will leave the CPU after the completion
             >  CPU will proceed with the next process in the ready queue / circular queue .
    else If process has burst time longer than 1 time slice/quantum
             >  Timer will be stopped . It cause interruption to the OS .
             >   Executed process is then placed at the tail of the circular / ready  querue by applying  the context                   switch
             >  CPU scheduler then proceeds by selecting the next process in the ready queue .        
Here , User can calculate the average turnaround time and average waiting time along with the starting and finishing time of each process


Turnaround time   :   Its the total time taken by the process between starting and the completion.(Completion Time-Arrival Time).

Waiting time         :   Its the time for which process is ready to run but not executed by CPU scheduler(Turnaround time-Burst time )
for example ,
we have three processes arrives at  0 ms.
     
                          Burst time             Waiting time         Turnaround time


P1                          20                          7                          (27-0)27

P2                          3                             4                            7

P3                          4                              7                           11

So here we can see the turnaround time for the process 1 is 30 while 7 and 10 for 2nd and 3rd process
 A Gantt chart is a chart which shows the start and finish times of  all the processes .use time Quantum 4ms.
  Gantt chart for the round robin algorithm with  is

  |--------|-------|-----|------|------|------|-----|
  |   P1    |    P2  | P3  |  P1  | P1  |  P1  | P1  |
  |--------|-------|-----|------|------|------|-----|
 0         4        7     11    15     19     23    27
The major features of the Round Robin algorithm is that

* Throughput is low as the large process is holding up the Central processing unit for execution .
* The main advantage of Round robin is to remove starvation  . As long as all processes completes the execution then we  dont have any trouble, But the problem starts when any of the process fails to complete . The incomplete   execution of any process leads to starvation .
* Queuing is done without using any prioritization of the processes.