Preemptive Round Robin C program
Hello Janine,
Once such program can be implemented using the following code:
#include<stdio.h>
int ttime,i,j,temp;
main()
{
       int pname[10],btime[10],pname2[10],btime2[10];
       int n,x,z;
       printf("Enter the no. of process:");
       scanf("%d",&n);
       printf("Enter the process name and burst time for the processn");
       for(i=0;i<n;i++)
       {    Â
   printf("Enter the process name:");
               scanf("%d",&pname2[i]);
               printf("Enter burst time for the process %d:",pname2[i]);
               scanf("%d",&btime2[i]);
       }
       printf("PROCESS NAME tt BURST TIMEn");
       for(i=0;i<n;i++)
          printf("%dttt %dn",pname2[i],btime2[i]);
          z=1;
       while(z==1)
       {
ttime=0;
       for(i=0;i<n;i++)
       {Â
pname[i]=pname2[i];
          btime[i]=btime2[i];
       }
Â
          printf ("PRESS 1.ROUND ROBIN 2.EXITn");
          scanf("%d",&x);
       switch(x)
       {
       case 1:
               rrobin(pname,btime,n);
               break;
       case 2:
               exit(0);
               break;
       default:
               printf("Invalid option");
              break;
      }
      printf("nn If you want to continue press 1:");
      scanf("%d",&z);
      }
}
    Â
 rrobin(int pname[],int btime[],int n)
      {
          int tslice;
          j=0;
          printf("nt ROUND ROBIN SCHEDULING nn");
          printf("Enter the time slice:n");
          scanf("%d",&tslice);
          printf("PROCESS NAME t REMAINING TIMEt TOTAL TIME");
   Â
Â
while(j<n)
          {Â
     for(i=0;i<n;i++)
{
     if(btime[i]>0)
                      {Â
if(btime[i]>=tslice)
                                 {Â
ttime+=tslice;
                                              btime[i]=btime[i]-tslice;
                                              printf("n%dtt %d tt %d",pname[i],btime[i],ttime);
                                              if(btime[i]==0)
                                               j++;
                                  }
                                  else
                                  {Â
ttime+=btime[i];
                                              btime[i]=0;
                                             printf("n%dtt %d tt %d",pname[i],btime[i],ttime);
                                  }
}
 }
      }
}
Â
If you want to check its output just go here: http://meansofmine.blogspot.com/2011/04/c-program-to-implement-round-robin.html
Regards,
Nicke
Â