ROUND ROBIN – C/C++ Operating System

As we all know that round robin is gonna be something hard for practicals. I have made a program and found a big one on internet. It is your preference to choose one. 😉

Here goes the Round Robin : Process execution in Operating System –

  • Each process gets a small unit of CPU time (time quantum q), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
  • If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
  • Timer interrupts every quantum to schedule next process
    Performance
  • q large -> FIFO
  • q small -> q must be large with respect to context switch, otherwise overhead is too high.

Picture1

Click below for program –  Program

#include<stdio.h>
#include<conio.h>
int main()
{
    int st[10],bt[10],wt[10],tat[10],n,tq;
    int i,count=0,swt=0,stat=0,temp,sq=0;
      float awt=0.0,atat=0.0;
      printf("Enter number of processes:");
      scanf("%d",&n);
      for(i=0;i<n;i++)
     {
         printf("\n\tEnter burst time for sequence %d :",i+1);
         scanf("%d",&bt[i]);
         st[i]=bt[i];
       }
       printf("Enter time quantum:");
       scanf("%d",&tq);
       while(1)
       {
         for(i=0,count=0;i<n;i++)
         {
               temp=tq;
               if(st[i]==0)
               {
                 count++;
                 continue;
              }
               if(st[i]>tq)
                st[i]=st[i]-tq;
               else if(st[i]>=0)
            {
                  temp=st[i];
                  st[i]=0;
            }
            sq=sq+temp;
            tat[i]=sq;
        }
         if(n==count)
             break;
    }
       for(i=0;i<n;i++)
       {
        wt[i]=tat[i]-bt[i];
        swt=swt+wt[i];
        stat=stat+tat[i];
       }
       awt=(float)swt/n;
    atat=(float)stat/n;
    for(i=0;i<n;i++)
        printf("\n\nProcess_no : %d\nBurst time:%d \nWait time : %d\nTurn around time : %d",i+1,bt[i],wt[i],tat[i]);
    printf("\nAvg wait time is %f \nAvg turn around time is %f",awt,atat);
    printf("\n\n\tProgramming in C#ODE Studio");
    getch();
}

rre

 

Leave a comment