Round Robin Scheduling

Write a C program to implement the various process scheduling mechanisms such as Round Robin Scheduling.
#include<stdio.h>
#include<conio.h>
struct process
{
 char pn[10];
 int bt,ct,time;
}p[10];
void main()
{
 int i,full,n,tq,wt[10],tat[10], time1=0;
 float avgwt=0.0;
 clrscr();
 printf("Enter number of processes:");
 scanf("%d",&n);
 printf("Enter process name and burst time of %d process\n", n);
 for(i=0;i<n;i++)
 {
 scanf("%s%d",&p[i].pn,&p[i].bt);
 p[i].time=p[i].bt;
 }
 printf("Enter quantum:");
 scanf("%d",&tq);
 full=n;
 while(full)
 {
 for(i=0;i<n;i++)
 {
 if(p[i].bt>=tq)
 {
 p[i].bt-=tq;
time1=time1+tq;
 }
 else if(p[i].bt!=0)
 {
 time1+=p[i].bt;
 p[i].bt=0;
 }
 else
 continue;
 if(p[i].bt==0)
 {
 full=full-1;
 tat[i]=time1;
 }
 }
 }
 for(i=0;i<n;i++)
 {
 p[i].ct=tat[i];
 wt[i]=tat[i]-p[i].time;
 }
 printf("----------------------------------\n");
 printf("PN\tBt\tCt\tTat\tWt\n");
 printf("----------------------------------\n");
 for(i=0;i<n;i++)
 {
 printf("%2s\t%2d\t%2d\t%2d\t%2d\n",p[i].pn,p[i].time,p[i].ct,tat[i],wt[i]);
 avgwt+=wt[i];
 }
 printf("----------------------------------\n");
 avgwt=avgwt/n;
 printf(" Average waiting time = %.2f\n",avgwt);
 printf("-----------------------------------\n");
 getch();
}
Output:

Comments

Post a Comment

Popular posts from this blog

Sequential File Allocation

Indexed File Allocation method

Linked File Allocation