please i want help for the coding of page replacement algorithms implemented in c language
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
what exactly do you mean by that? what operating system? what kind of printer ? what font? any graphics? any lines? If you search www.codeproject.com you will find a few c++ classes for laser printers that do all sorts of fancy things in MS-Windows.
DangerDev 107 Posting Pro in Training
hi
make a link list of pageinfo having following as node
Node{
TimeStamp t;
PtrToPage ptr;
}
now on the basis of this u can implement various available page replacement policy.
some are here:
http://en.wikipedia.org/wiki/Page_replacement_algorithm
http://www.sci.csuhayward.edu/~billard/cs4560/node15.html
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Oh, I get it now. I apparently completly misunderstood the question.
rathmal 0 Newbie Poster
write a program in c language to implement
page replacement algorithms like FIFO, optimal page replacement and LRU
DangerDev 107 Posting Pro in Training
No Homework, try u'r self
Rachnamb 0 Newbie Poster
please i want help for the coding of page replacement algorithms implemented in c language
Here are some programs u can refer..SJNalg..
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define SIZE 50
float w[SIZE],t[SIZE],tavg,wavg,avg=0.0,avg1=0.0;
int b[SIZE],b1[SIZE],i,n,ch,ch1;
void main()
{
clrscr();
printf("\n\t******Scheduling Algorithms******\t\n");
do
{
printf(" 1.Enter Input Values\n 2.Display Input Table\n 3.Turn around time\n 4.Waiting Time\n 5.GANNT CHART\n 6.EXIT");
printf("Enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1 : printf("Enter the number of processes:");
scanf("%d",&n);
printf("\nEnter the processes burst times\n");
for(i=0;i<n;i++)
{
printf("Enter the burst time of process%d:",i);
scanf("%d",&b1[i]);
}
for(i=0;i<n;i++)
{
b[i]=b1[i];
}
for(i=0;i<n;i++)
for(int j=0;j<n;j++)
if(b[i]<b[j])
{
int temp=b[i];
b[i]=b[j];
b[j]=temp;
}
break;
case 2: printf("The Input table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b1[i]);
}
printf("The sorted table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b[i]);
}
break;
case 3: t[0]=b[0];
for(i=1;i<n;i++)
{
t[i]=t[i-1]+b[i];
}
printf("\tProcess \tTurnAround time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%f \n",i,t[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
avg+=t[i];
}
tavg=avg/n;
printf("Average turn around time %f:\n",tavg);
break;
case 4:
w[0]=0;
for(i=1;i<n;i++)
{
w[i]=t[i-1];
}
printf("\tProcess \t Waiting time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%f \n",i,w[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
avg1+=w[i];
}
wavg=avg1/n;
printf("Average waiting time%f:\n",wavg);
break;
case 5: int gd=DETECT,gm;
int x1,y1,x2,y2;
x1=y1=100;
y2=150;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setbkcolor(5);
outtextxy(250,250,"GANNT CHART");
for(i=0;i<n;i++)
{
rectangle(x1,y1,x1+b[i],y2);
x1=x1+b[i];
}
//x2=x2+b[i];
for(i=0;i<n;i++)
{
outtextxy(x1+5,y2+5,itoa(i,"t[i]",100));
outtextxy((x1+(x2-x1)/2),125,itoa(b[i],"p", 10));
}
break;
case 6 : exit(0);
break;
default : exit(0);
}
}while(ch!=0);
}
//
//RoundRobin..
#include<conio.h>
#include<stdio.h>
void main()
{
int n,i,q,next=-1,x,k=0;
float BT[20],TT[20],BTvar,sum=0.0,WT[20];
float awt=0,att=0;
printf("Enter the number of processes\n");
scanf("%d",&n);
printf("\n Enter burst time \n");
for(i=0;i<n;i++)
{scanf("%f",&BT[i]);
BTvar=BTvar+BT[i];
}
printf("\n Enter the quantum time of CPU\n");
scanf("%d",&q);
do
{ //1
next++;
if(next>n)
next=0;
if(BT[next]!=0)
{ //2
if(BT[next]<q)
{ //3
k=k+BT[next]; BT[next]=0;
} //3
else
{ //4
BT[next]=BT[next]-q;
k=k+q;
} //4
if(BT[next]==0)
{ //5
TT[next]=k;
sum+=TT[next];
} //5
}
}while(sum<BTvar); //1
printf("\n Turnaround time \n ");
for(i=0;i<n;i++)
{
printf(" P%d = %d \t TT%d = %f \n",i,i,i,TT[i]);
att+=TT[i];
}
WT[0]=0;
k=0;
printf("\n Waiting time \n");
for(i=1;i<n;i++)
{
if(TT[i-1]<q)
WT[i]=TT[i-1];
else
WT[i]=k+q;
k+=WT[i];
}
for(i=0;i<n;i++)
{
printf("P%d = %d \t WT%d= %f \n",i,i,i,WT[i]);
awt+=WT[i];
}
printf("\n Average Waiting time = %f : ",(awt/n));
printf("\n Aveage Turnaroundtime = %f : ",(att/n));
getch();
}
OUTPUT:
Enter the number of processes
3
Enter burst time
25
50
100
Enter the quantum time of CPU
25
Turnaround time
P0 = 0 TT0 = 25.000000
P1 = 1 TT1 = 100.000000
P2 = 2 TT2 = 175.000000
Waiting time
P0 = 0 WT0= 0.000000
P1 = 1 WT1= 25.000000
P2 = 2 WT2= 50.000000
Average Waiting time = 25.000000 :
Aveage Turnaroundtime = 100.000000 :
Edited by mike_2000_17 because: Fixed formatting
Rachnamb 0 Newbie Poster
Here's preemptive page replacement alg..
#include<stdio.h>
#include<conio.h>
int i,j,k,n,a[20],b[20],c[20],u[10];
int m=0,temp,tt,t,tp;
float var=0.0;
void main()
{
printf("Enter the number of jobs\n");
scanf("%d",&n);
printf("\nEnter the order of jobs entering the queue\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the burst time for each job\n");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
printf("Enter the priority of each job\n");
for(i=0;i<n;i++)
scanf("%d",&c[i]);
for(i=0;i<n;i++)
for(j=1;j<n;j++)
for(k=0;k<n;k++)
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=c[i];
tp=a[i];
a[i]=a[j];
a[j]=tp;
t=b[i];
b[i]=b[j];
b[j]=t;
}
printf("\n_____________________________________________\n");
for(i=n-1;i>=0;i--)
{
printf(" %d", a[i]);
printf(" || ");
}
printf("\n_____________________________________________\n");
j=0;
printf("%d",j);
u[0]=0;
for(k=n-1;k>=0;k--)
{
j+=b[k];
u[m]=j;
m++;
var+=j;
printf(" %d",j);
}
t=0;
temp=0;
k=0;
printf("\n Waiting time \t turnaround time \n");
for(m=n-1;m>=0;m--)
{
t=u[m];
m--;
tt=u[m];
m++;
printf("\n job %d: \t %d \t %d\n",a[k],tt,t);
k++;
}
printf("\n Avg TAT = %f\n",(var/n));
printf("Avg WT = %f\n",(var-j)/n);
getch();
}
//Try one more..
#include<stdio.h>
#include<conio.h>
void main()
{int b1[10],b[10],i,n,j,temp;
printf("Enter the num \n");
scanf("%d",&n);
printf("Enter the burst time of process%d:",i);
for(i=0;i<n;i++)
scanf("%d",&b1[i]);
for(i=0;i<n;i++)
{
b[i]=b1[i];
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
printf("The Input table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b1[i]);
}
printf("The sorted table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b[i]);
}
getch();
}
Rachnamb 0 Newbie Poster
c ya
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.