RR Round Robin Process Scheduling Algorithm In C Program

Ram Pothuraju
#include< stdio.h>
#include< conio.h>
void main()
{

 int njob,pID[15],aTime[15],bTime[15],jTime[15],taTime[15],wTime[15],i,j,temp,sTime[15],aBtime[15];
 int texe=0,qtime,aexe=0;
 float totalWait,totalTA;
 clrscr();
 printf("\n Enter number of process:");
 scanf("%d",&njob);
 

 printf("\n Enter quantum time:");
 scanf("%d",&qtime);
 for(i=0;i< njob;i++)
 {
  printf("\n Enter Burst time for process[%d]:",i);
  scanf("%d",&bTime[i]);
  aBtime[i]=bTime[i];
 
 }

 //count total exe time

 for(i=0;i< njob;i++)
 {
  texe=texe+bTime[i];
 }
 
 printf("%d",texe);

 //Execute Round robin for given quantum time

 while(aexe< texe)
 {
  for(i=0;i< njob;i++)
  {
   if(bTime[i]>=qtime)
   {
    aexe=aexe+qtime;
    bTime[i]=bTime[i]-qtime;
    jTime[i]=aexe;
   }
   else
   {
    if(bTime[i]!=0)
    {
     aexe=aexe+bTime[i];
     bTime[i]=0;
     jTime[i]=aexe;
    }
   }
  }
 }



 for(i=0;i< njob;i++)
 {
  wTime[i]=jTime[i]-aBtime[i];
 }

 printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_");
 printf("\n| process |\t burst time |\t Waiting time |\t TA time|");
  printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_");
 for(i=0;i< njob;i++)
 {
  printf("\n|    %d    |\t     %d \t    |\t\t    %d |\t\t     %d|",i,aBtime[i],wTime[i],jTime[i]);

  totalTA=totalTA+jTime[i];
  totalWait=totalWait+wTime[i];
 }

 printf("\n_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_");
 
 printf("\n total waiting time:%.2f",totalWait/njob);
 printf("\n total turn around time:%.2f",totalTA/njob);
getch();
}


OUTPUT

Enter number of process:3

 Enter quantum time:4

 Enter Burst time for process[0]:24

 Enter Burst time for process[1]:3

 Enter Burst time for process[2]:3
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_
| process |      burst time |    Waiting time |  TA time|
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_
|    0    |          24     |               6         30|
|    1    |          3      |               4 |        7|
|    2    |          3      |               7 |       10|
_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_
 total waiting time:5.67
 total turn around time:15.67

Post a Comment

0Comments

Post a Comment (0)