#include < stdio.h >
#include < conio.h >
void main()
{
int a[20],c[20],page[20];
int i,j,k,f,n;
int count=0;fault=0,hit=0;
clrscr();
printf("Enter reference string length : ");
scanf("%d",&n);
printf("Enter reference string");
for(i=0;i < n;i++)
scanf("%d",&page[i]);
printf("Enter frame size ");
scanf("%d",&f);
for(i=0;i < f;i++)
{
for(j=0;j < fault;j++)
{
if(page[i]==a[j])
{
hit++;
c[j]=++count;
goto xyz;
}
}
a[i]=page[i];
fault++;
c[i]=++count;
xyz: ;
}
Thursday, April 29, 2010
Round Robin program using C
#include < stdio.h >
#include < conio.h >
void main()
{
int t1=0,wt,twt=0,tat=0,n,i,j,tq,c=0;
int bt[10],a[10],f[10],b[10];
clrscr();
printf("\n enter no of process: ");
scanf("%d",&n);
for(i=0;i < n;i++)
{
f[i]=0; /* indicates process is completed if f[i]==1 */
a[i]=i+1; /* indicates process names */
}
for(i=0;i < n;i++)
{
printf("Enter the Burst time of process %d ",i+1);
scanf("%d",&bt[i]);
b[i]=bt[i];
}
printf("enter the time quantum : ");
scanf("%d",&tq);
printf("given burst times are:\n");
for(i=0;i < n;i++)
{
printf("%d\t",bt[i]);
}
i=0;
while(c < n)
{
if(bt[i]<=tq && f[i]==0)
{
t1=t1+bt[i];
printf("\n turn around time of p%d is : %d",a[i],t1);
wt=t1-b[i];
printf("\n Waiting time of p%d is : %d",a[i],wt);
tat=tat+t1;
twt=twt+wt;
f[i]=1;
c++; /* indicating how many processes are completing */
}
else
{
if(f[i]==0)
{
bt[i]=bt[i]-tq;
t1=t1+tq;
}
}
i=(i+1)%n; */ for rotating value of */
}
printf("\n\n Avg turn around time is : %d\n",tat/n);
printf("\n\n Avg Waiting time is : %d",twt/n);
getch();
}
Output:
Enter no of process : 3
Enter the Burst time of process 1 : 20
Enter the Burst time of process 2 : 5
Enter the Burst time of process 3 : 3
Enter time quantum : 4
Given burst times are :
20 5 3
turn around time of p3 is : 11
Waiting time of p3 is : 8
turn around time of p2 is : 16
Waiting time of p2 is : 11
turn around time of p1 is : 28
Waiting time of p1 is :8
Avg turn arround time is : 18
Avg waiting time is : 9
#include < conio.h >
void main()
{
int t1=0,wt,twt=0,tat=0,n,i,j,tq,c=0;
int bt[10],a[10],f[10],b[10];
clrscr();
printf("\n enter no of process: ");
scanf("%d",&n);
for(i=0;i < n;i++)
{
f[i]=0; /* indicates process is completed if f[i]==1 */
a[i]=i+1; /* indicates process names */
}
for(i=0;i < n;i++)
{
printf("Enter the Burst time of process %d ",i+1);
scanf("%d",&bt[i]);
b[i]=bt[i];
}
printf("enter the time quantum : ");
scanf("%d",&tq);
printf("given burst times are:\n");
for(i=0;i < n;i++)
{
printf("%d\t",bt[i]);
}
i=0;
while(c < n)
{
if(bt[i]<=tq && f[i]==0)
{
t1=t1+bt[i];
printf("\n turn around time of p%d is : %d",a[i],t1);
wt=t1-b[i];
printf("\n Waiting time of p%d is : %d",a[i],wt);
tat=tat+t1;
twt=twt+wt;
f[i]=1;
c++; /* indicating how many processes are completing */
}
else
{
if(f[i]==0)
{
bt[i]=bt[i]-tq;
t1=t1+tq;
}
}
i=(i+1)%n; */ for rotating value of */
}
printf("\n\n Avg turn around time is : %d\n",tat/n);
printf("\n\n Avg Waiting time is : %d",twt/n);
getch();
}
Enter the Burst time of process 1 : 20
Enter the Burst time of process 2 : 5
Enter the Burst time of process 3 : 3
Enter time quantum : 4
Given burst times are :
20 5 3
turn around time of p3 is : 11
Waiting time of p3 is : 8
turn around time of p2 is : 16
Waiting time of p2 is : 11
turn around time of p1 is : 28
Waiting time of p1 is :8
Avg turn arround time is : 18
Avg waiting time is : 9