You are on page 1of 17

ROUND ROBIN

#include<stdio.h>
#include<conio.h>
void main()
{
int job[10],bt[10],wt[10],tat[10]={0},n,i,j,k,rt[10],q,timeunit=0;
float atat=0,awt=0;
clrscr();
printf("Enter no of jobs");
scanf("%d",&n);
printf("job\tburst time\n");
for(i=0;i<n;i++)
scanf("%d%d",&job[i],&bt[i]);
printf("\nEnter the time quantum");
scanf("%d",&q);
for(k=0;k<n;k++)
{
for(i=0;i<n;i++)
rt[i]=bt[i];
while(1)
{
for(i=0;i<n;i++)
{
if(rt[k]==0)
goto P;
else if(rt[i]>=q)
{
tat[k]+=q;
rt[i]-=q;
}
else if(rt[i]>0)
{
tat[k]+=rt[i];
rt[i]=0;
}
}
}
P:atat+=tat[k];
wt[k]=tat[k]-bt[k];
awt+=wt[k];
}
for(i=0;i<n;i++)
{
timeunit+=bt[i];
}
printf("\njob\tbt\twt\ttat\n");
for(i=0;i<n;i++)
printf("\n%d\t%d\t%d\t%d\t",job[i],bt[i],wt[i],tat[i]);
printf("\nAverage turn around time is %f",(float)atat/n);
printf("\nAverage waiting time is %f",(float)awt/n);
getch();
}
SJF
#include<stdio.h>
#include<conio.h>
void main()
{
int bt[5],wt=0,tat=0,n,i,job[5],ttat=0,twt=0,temp1,temp2,j;
float atat,awt;
clrscr();
printf("Enter no of jobs");
scanf("%d",&n);
printf("Enter Burst times");
for(i=0;i<n;i++)
scanf("%d",&bt[i]);
for(i=0;i<n;i++)
job[i]=i+1;
//printf("\njobs\tbt\ttat\ttwt\n");
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(bt[i]>bt[j])
{
temp1=bt[i];
bt[i]=bt[j];
bt[j]=temp1;
temp2=job[i];
job[i]=job[j];
job[j]=temp2;
}
}
}
printf("job\tbt\ttat\twt\n");
for(i=0;i<n;i++)
{
tat+=bt[i];
ttat+=tat;
printf("%d\t%d\t%d\t%d\n",job[i],bt[i],tat,wt);
twt+=wt;
wt=tat;
}
atat=(float)ttat/n;
awt=(float)twt/n;
printf("Average turn around time =%f\n",atat);
printf("Average waiting time =%f\n",awt);
getch();
}
FCFS
#include<stdio.h>
#include<conio.h>
void main()
{
int bt[5],wt=0,tat=0,n,i,job[5],ttat=0,twt=0;
float atat,awt;
clrscr();
printf("Enter no of jobs");
scanf("%d",&n);
printf("Enter Burst Times\n");
for(i=0;i<n;i++)
scanf("%d",&bt[i]);
for(i=0;i<n;i++)
job[i]=i+1;
printf("job\tbt\ttat\twt\n");
for(i=0;i<n;i++)
{
tat+=bt[i];
ttat+=tat;
printf("%d\t%d\t%d\t%d\n",job[i],bt[i],tat,wt);
twt+=wt;
wt=tat;
}
atat=(float)ttat/n;
awt=(float)twt/n;
printf("Average turn around time =%f\n",atat);
printf("Average waiting time =%f\n",awt);
getch();
}
PRIORITY
#include<stdio.h>
#include<conio.h>
main()
{
int bt[10],wt=0,tat=0,n,i,j,temp1,temp2,temp3,job[10],p[10];
float atat,awt;
int ttat=0,twt=0;
clrscr();
printf("\n enter number of jobs");
scanf("%d",&n);
printf("job \t bursttime\t prriority\n");
for(i=0;i<n;i++)
scanf("%d%d%d",&job[i],&bt[i],&p[i]);
printf("\n job \t bt\t wt\t tat\n");
for(i=0;i<n;i++)
{
for(j=i+1;j< n;j++)
{
if(p[i]>p[j])
{
temp1=p[i];
p[i]=p[j];
p[j]=temp1;
temp2=job[i];
job[i]=job[j];
job[j]=temp2;
temp3=bt[i];
bt[i]=bt[j];
bt[j]=temp3;
}
}
}
for(i=0;i<n;i++)
{
tat+=bt[i];
ttat+=tat;
printf("\n %d\t %d\t %d\t %d",job[i],bt[i],tat,wt);
twt+=wt;
wt=tat;
}
atat=(float)ttat/n;
awt=(float)twt/n;
printf("\n average turn around time:%f\n",atat);
printf("\n average waiting time:%f\n",awt);
getch();
}

SEQUENTIAL FILE ALLOCATION }


void fill_space()
#include<graphics.h>
{
#include<stdlib.h>
int i,b,x1,y1;
#include<stdio.h>
for(i=0;i<n;i++)
#define bl 30
{
#define bw 15
for(b=f[i].st_blk;b<(f[i].st_blk+f[i].len);b++)
#define sx 150
{
#define sy 100
if(i>0&&(f[i].st_blk>f[i-1].st_blk&&f[i].st_blk<f[i-1].len))
typedef struct
{
{
outtextxy(320,40,"File already Exists in this Location");
char name[10];
}
int st_blk;
else{
int len,fcolour;
setfillstyle(1,f[i].fcolour);
}file_info;
x1=sx+(b%7)*50;
int cols[]={GREEN,MAGENTA,BLUE,CYAN,RED};
y1=sy+(b/7)*40;
file_info f[10];
bar3d(x1,y1,x1+bl,y1+bw,0,0);}
int n;
}
void read_files()
}
{int i;
}
printf("\nHow many files");
void design_disk()
scanf("%d",&n);
{
printf("\nEnter the details");
int i,j,x1,y1;
for(i=0;i<n;i++){
char s[5];
printf("\nFile name");
setcolor(LIGHTGREEN);
fflush(stdin);
settextjustify(1,1);
gets(f[i].name);
outtextxy(320,20,"contiguous file allocation");
printf("Starting block");
setcolor(14);
scanf("%d",&f[i].st_blk);
settextstyle(2,0,3);
printf("length");
settextjustify(1,4);
scanf("%d",&f[i].len);
for(i=0;i<7;i++)
f[i].fcolour=cols[i];
{
}
for(j=0;j<7;j++) setcolor(14);
{ }
x1=sx+j*50; void main()
y1=sy+i*40; {
rectangle(x1,y1,x1+bl,y1+bw); int gd,gm;
sprintf(s,"%d",i*7+j); gd=DETECT;
outtextxy(x1+bl/2,y1+bw+10,s); initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
} randomize();
} read_files();
rectangle(sx-20,sy-20,sx+350,sy+280); cleardevice();
settextstyle(1,0,2); design_disk();
for(i=0;i<n;i++) fill_space();
{ getch();
setcolor(f[i].fcolour); closegraph();
outtextxy(100,400+i*15,f[i].name); }
}

INDEXED FILE ALLOCATION for(i=1;i<6;i++)


{
#include<stdio.h>
n=blocks_allocated[i];
#include<graphics.h>
setcolor(14);
#include<conio.h>
bar3d(b[n].x1,b[n].y1,b[n].x2,b[n].y2,0,0);
#include<stdlib.h>
draw_link_lines(blocks_allocated[0],blocks_allocated[i]);
#define bl 30
sleep(1);
#define bw 15
}
#define sx 140
}
#define sy 100
void crea_block(int bno,block *bp)
typedef struct
{
{
bp->row=bno/7;
int x1,y1,x2,y2,row,col;
bp->col=bno%7;
}block;
bp->x1=sx+(bno%7)*50;
typedef struct
bp->y1=sy+(bno/7)*40;
{
bp->x2=bp->x1+bl;
char name[10];
bp->y2=bp->y1+bw;
int st_blk;
}
int len,fcolor;
design_disk()
}file_info;
{
void draw_link_lines(int st,int end);
int i,j,x1,y1;
file_info f={"ABC.TXT",10,7,RED};
char s[5];
int blocks_allocated[7]={30,2,18,27,44,61};
setcolor(LIGHTGREEN);
block b[63];
settextstyle(1,0,3);
fill_space()
settextjustify(1,1);
{
outtextxy(320,20,"Index Alloxation");
int i,n;
setcolor(14);
setfillstyle(1,LIGHTMAGENTA);
settextstyle(2,0,3);
n=blocks_allocated[0];
settextjustify(1,1);
bar3d(b[n].x1,b[n].y1,b[n].x2,b[n].y2,0,0);
for(i=0;i<63;i++)
setfillstyle(1,f.fcolor);
{
setcolor(LIGHTCYAN);
crea_block(i,&b[i]);
circle(b[n].x1+15,b[n].y1+7,18);
rectangle(b[i].x1,b[i].y1,b[i].x2,b[i].y2);
sprintf(s,"%d",i); lineto(getx(),b[end].y1+10);
outtextxy(b[i].x1+bl/2,b[i].y1+bw+10,s); line(b[end].x1,b[end].y1+10,b[end].x1-5,b[end].y1+5);
} line(b[end].x1,b[end].y1+10,b[end].x1-5,b[end].y1+15);
rectangle(sx-20,sy-20,sx+350,sy+360); }
settextstyle(1,0,2); void main()
setcolor(14); {
} int gd,gm;
void draw_link_lines(int st,int end) gd=DETECT;
{ initgraph(&gd,&gm,"c:\\turboc3\\BGI");
int row,col,x; randomize();
while((x=random(16))==0) cleardevice();
continue; sleep(2);
setcolor(x); design_disk();
moveto(b[st].x2,b[st].y1+7); fill_space();
linerel(10,0); getch();
lineto(getx(),b[end].y1-10); closegraph();
lineto(b[end].x1-10,gety()); }

LINKED FILE ALLOCATION settextstyle(2,0,4);


setcolor(GREEN);
#include<graphics.h>
rectangle(500,200,580,300);
#include<stdio.h>
line(580,200,580,300);
#include<conio.h>
line(500,230,639,230);
#define bl 30
line(500,260,639,260);
#define bw 15
settextjustify(0,1);
#define sx 140
outtextxy(506,200,"filename");
#define sy 100
outtextxy(585,220,f.name);
typedef struct
outtextxy(505,250,"st.block");
{
sprintf(s,"%d",f.st_blk);
int x1,y1,x2,y2,row,col;
outtextxy(505,280,"length");
}block;
sprintf(s,"%d",f.len);
typedef struct
outtextxy(595,280,s);
{
}
char name[10];
void fill_space() {
int st_blk,len,fcolor;
int i,n;
}file_info;
for(i=0;i<f.len;i++)
void draw_link_lines(int st,int end);
{
file_info f={"ABC.txt",28,7,CYAN};
n=blocks_allocated[i];
int
setfillstyle(1,i==0?RED:f.fcolor);
blocks_allocated[63]={28,16,31,33,38,55,56,29,1,30,48,12,19,
bar3d(b[n].x1,b[n].y1,b[n].x2,b[n].y2,0,0);
20,21,22,39,40,18,2,10,50,51,52,54,17,35,43,13,3,15,36,49,24,
if(i<f.len-1)
4,6,14,16,25,37,5,56,11,26,9,27,45,55,23,34,41,42,59,8,53};
draw_link_lines(blocks_allocated[i],blocks_allocated[i+1]);
block b[63];
sleep(1);
void read_file_info() {
}
printf("Enter the file name");
}
fflush(stdin);
void crea_block(int bno,block *bp) {
gets(f.name);
bp->row=bno/7;
printf("\nLength");
bp->col=bno/7;
scanf("%d",&f.len);
bp->x1=sx+(bno%7)*50;
}
bp->y1=sy+(bno/7)*40;
void create_info_table() {
bp->x2=bp->x1+bl;
int i; char s[5];
bp->y2=bp->y1+bw;
} setcolor(RED);
void design_disk() { moveto(b[st].x2,b[st].y1+7);
int i,j,x1,y1; linerel(10,0);
char s[5]; lineto(getx(),b[end].y1-10);
setcolor(RED); lineto(b[end].x1-10,gety());
settextstyle(1,0,3); lineto(getx(),b[end].y1+10);
settextjustify(1,1); lineto(b[end].x1,b[end].y1+10);
outtextxy(320,20,"linked file Allocation"); line(b[end].x1,b[end].y1+10,b[end].x1-5,b[end].y1+5);
setcolor(14); line(b[end].x1,b[end].y1+10,b[end].x1-5,b[end].y1+15);
settextstyle(2,0,3); }
settextjustify(1,1); void main() {
for(i=0;i<63;i++) int gd,gm;
{ gd=DETECT;
crea_block(i,&b[i]); initgraph(&gd,&gm,"c:\\turboc3\\BGI");
rectangle(b[i].x1,b[i].y1,b[i].x2,b[i].y2); cleardevice();
sprintf(s,"%d",i); sleep(2);
outtextxy(b[i].x1+bl/2,b[i].y1+bw+10,s); read_file_info();
} design_disk();
rectangle(sx-20,sy-20,sx+350,sy+350); fill_space();
settextstyle(1,0,1); create_info_table();
setcolor(53); getch();
} closegraph();
void draw_link_lines(int st,int end) { }
int row,col;

MVT
#include<stdio.h>
int main()
{
int i,m,n,tot,s[20];
printf("enter the total memory size:");
scanf("%d",&tot);
printf("enter number of page:");
scanf("%d",&n);
printf("enter memory for os:");
scanf("%d ",&m);
for(i=0;i<n;i++)
{
printf("enter the size of page %d",i+1);
scanf("%d ",&s[i]);
}
tot=tot-m;
for(i=0;i<n;i++)
{
if(tot>=s[i])
{
printf("allocate page %d \n",i+1);
tot=tot-s[i];
}
else
printf("process p %d is blocked \n",i+1);
}
printf("total external fragmentation=%d\n",tot);
getch();
}
MFT
#include<stdio.h>
#include<conio.h>
void main()
{
int ms,i,ps[20],n,size,p[20],s,intr=0;
clrscr();
printf(" Enter Memory for size ");
scanf("%d",&ms);
printf("\n Enter Memory for OS ");
scanf("%d",&s);
ms-=s;
printf("\n Enter no of partitions to be divided ");
scanf("%d",&n);
size=ms/n;
for(i=0;i<n;i++)
{
printf("\n Enter process & process size ");
scanf("%d%d",&p[i],&ps[i]);
if(ps[i]<=size)
{
intr=intr+size-ps[i];
printf("\n Process % is allocated ",p[i]);
}
else
printf(" Process %d is Blocked ",p[i]);
}
printf(" Total fragmentation is %d ",intr);
getch();
}
SINGLE LEVEL DIRECTORY
//single level directory structure
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#define SX 150
#define SY 200
#define BL 30
#define BW 15
int n;
char a[10][10];
int cols[]={2,5,1,3,4,6,8,7,9};
void readfiles()
{
int i;
printf("\nEnter no. of directories:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter file name:");
scanf("%s",&a[i]);
}
}
void fillspace()
{
int x1,y1,i;
outtextxy(70,205,"Directory");
outtextxy(100,255,"Files");
for(i=0;i<n;i++)
{
setfillstyle(1,cols[i]);
x1=SX+(i%10)*40;
y1=SY+(i/10)*40;
bar(x1,y1,x1+BL,y1+BW);
outtextxy(x1+BL/4,y1+BW/4,a[i]);
line(x1+BL/2,y1+BW,x1+BL/2,y1+50);
circle(x1+BL/2,y1+60,7);
}
}
void main()
{
int gm,gd=DETECT;
initgraph(&gd,&gm,"c:\\tc\\bgi");
readfiles();
fillspace();
getch();
closegraph();
}

TWO LEVEL DIRECTORY scanf("%d",&m[i]);


for(j=0;j<m[i];j++)
//two level directory structure
{
#include<stdio.h>
printf("enter %d file name:",j+1);
#include<conio.h>
scanf("%s",&f[i].k[j].file);
#include<graphics.h>
}
#define SX 250
}
#define SY 200
}
#define BL 30
void fillspace()
#define BW 15
{
#define SY1 250
int x1,y1,i,j;
int SX1=100;
outtextxy(70,205,"Directory");
int n,m[10];
outtextxy(100,255,"Files");
char a[10][10];
for(i=0;i<n;i++)
int cols[]={2,5,1,3,4,6,8,7,9};
{
typedef struct
setfillstyle(1,cols[i]);
{
x1=SX+(i%10)*50;
char name[10];
y1=SY+(i/10)*40;
struct
bar(x1,y1,x1+BL+20,y1+BW);
{
outtextxy(x1+BL/4,y1+BW/4,f[i].name);
char file[10];
line(x1+BL/2,y1+BW,SX1+50,SY1);
}k[10];
SX1=SX1+50;
}file_info;
for(j=0;j<m[i];j++)
file_info f[10];
{ setfillstyle(1,cols[i]);
void readfiles()
x1=SX1+(j%10)*40;
{
y1=SY1+(j/10)*40;
int i,j;
bar(x1,y1,x1+BL+10,y1+BW);
printf("\nEnter no. of directories:");
outtextxy(x1+BL/4,y1+BW/4,f[i].k[j].file);
scanf("%d",&n);
line(x1+BL/2,y1+BW,x1+BL/2,y1+50);
for(i=0;i<n;i++)
circle(x1+BL/2,y1+60,7);
{
}
printf("Enter %d directory:",i+1);
SX1=SX1+100;
scanf("%s",&f[i].name);
}
printf("enter no.of files:");
}
void main() getch();
{ fillspace();
int gm,gd=DETECT; getch();
initgraph(&gd,&gm,"c:\\tc\\bgi"); closegraph();
readfiles(); }
cleardevice();

DEAD LOCK AVOIDANCE for(l=0;l<n;l++)


{
#include<stdio.h>
cou=0;
#include<conio.h>
flag=0;
#include<stdlib.h>
for(i=0;i<n;i++)
#include<dos.h>
{
#define s 15
cou=0;flag=0;
void main()
for(j=0;j<m;j++)
{
if(a[j]>=r[i][j])
int n,m,a[s],e[s],c[s][s],r[s][s],i,j,k,cou,l,flag,count;
{
void input(int n,int m,int t[s][s]);
cou++;
clrscr();
if(c[i][j]==-1)
cou=flag=count=0;
flag++;
printf("\nenter no of processors:");
}
scanf("%d",&n);
if(cou==m)
printf("enter the no of resource classes:");
{
scanf("%d",&m);
if(flag!=m)
for(i=0;i<m;i++)
{
{
printf("\nprocess %d is satisfied",i+1);
printf("\nenter instance of resourcce class %d(resource in
count++;
existance):",i+1);
for(k=0;k<m;k++)
scanf("%d",&e[i]);
{
printf("\nenter free vector of resource class %d(resources
a[k]+=c[i][k];
available):",i+1);
printf("\na[%d]=%d\t",k,a[k]);
scanf("%d",&a[i]);
getch();
}
c[i][k]=-1;
printf("\nenter the current allocation matrix\n");
}
for(i=0;i<n;i++)
}
for(j=0;j<m;j++)
}
scanf("%d",&c[i][j]);
getch();
printf("\nenter the request matrix:");
}
for(i=0;i<n;i++)
}
for(j=0;j<m;j++)
if(count==n)
scanf("%d",&r[i][j]);
printf("\nprocess are completed\n");
else getch();
printf("\n a safe state occurs\n"); }

DEAD LOCK DETECTION for(i=1;i<=4;i++)


{
#include<stdio.h>
sum=0;
#include<conio.h>
for(j=1;j<=5;j++)
void main()
{
{
sum+=p[i][j];
int
}
found,flag,l,p[4][5],tp,c[4][5],i,j,k=1,m[5],a[5],r[5],temp[5],su
if(sum==0)
m=0;
{
clrscr();
m[k]=i;
printf("\nenter total no of process:");
k++;
scanf("%d",&tp);
}
printf("\nenter clain matrix:");
}
for(i=1;i<=4;i++)
for(i=1;i<=4;i++)
for(j=1;j<=5;j++)
{
{
for(l=1;l<l;l++)
scanf("%d",&c[i][j]);
if(i!=m[l])
}
{
printf("enter allocation matrix:");
flag=1;
for(i=1;i<=4;i++)
for(j=i;j<=5;j++)
for(j=1;j<=5;j++)
if(c[i][j]>temp[j])
{
{
scanf("%d",&p[i][j]);
flag=0;
}
break;
printf("enter resources vector:\n");
}
for(i=1;i<=5;i++)
}
{
if(flag==1)
scanf("%d",&r[i]);
{
}
m[k]=i;
printf("enter availability vector:\n");
k++;
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
{
temp[j]+=p[i][j];
scanf("%d",&a[i]);
}
temp[i]=a[i];
}
}
printf("\ndead lock causing process are:");
for(j=1;j<=tp;j++) }
{ if(found==0)
found=0; printf("%d\t",j);
for(i=l;i<k;i++) }
{ getch();
if(j==m[i]) }
found=1;

FIFO PAGE REPLACEMENT


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#define MAX 3
void insertq(int);
int queue[MAX],front,rear;
void main()
{
char choice;
int n,i,flag;
clrscr();
front=rear=0;
cout<<"\npage replacement fifo\n";
do
{
flag=0;
cout<<"\nEnter page pagenumber to be inserted:";
cin>>n;
for(i=0;i<rear;i++)
if(queue[i]==n)
flag=1;
if(flag==0)
insertq(n);
else
cout<<"\npage edists in memory";
cout<<"\npages in memory\n";
for(i=0;i<rear;i++)
cout<<queue[i]<<"\t";
cout<<"\ndo you want to insert pages if yes\n";
cin>>choice;
}
while(choice=='y');
}
void insertq(int page)
{
if(rear==MAX)
{
if(front==MAX)
front=0;
queue[front]=page;
cout<<"\nmemory is full page in position"<<front<<"is replaced";
front++;
}
else
{
queue[rear]=page;
rear++;
}
}

LRU PAGE REPLACEMENT }


cout<<"\npages in memory:";
#include<iostream.h>
for(j=0;j<part;j++)
#include<stdio.h>
{
#include<conio.h>
cout<<mem[j]<<"\t";
class lru
}
{
tm=i;
private:
do
int n,part,len,mem[20],pages[20],time[20];
{
int pagefault;
flag=0;
public:
for(j=0;j<part;j++)
void getdata();
{
void replace();
if(mem[j]==pages[i])
};
{
void lru::getdata()
flag=1;
{
time[pages[i]]=tm;
int i;
}
cout<<"\nEnter no of partitions in memory:";
}
cin>>part;
if(flag==1)
cout<<"\nEnter the length of reference string:";
{
cin>>len;
cout<<"\npage exists in memory:";
for(i=0;i<len;i++)
i++;
cin>>pages[i];
}
}
else
void lru::replace()
{
{
min=999;
int i,j,tm,flag,min,pos;
for(j=0;j<part;j++)
pagefault=0;
{
for(j=0;j<20;j++)
if(time[mem[j]]<min)
time[j]=999;
{
for(i=0;i<part;i++)
min=time[mem[j]];
{
pos=j;
mem[i]=pages[i];
}
time[pages[i]]=i;
}
pagefault++;
mem[pos]=pages[i];
time[pages[i]]=tm; cout<<"\nno of page fault:"<<pagefault;
pagefault++; }
cout<<"\npages in memory:"; void main()
for(j=0;j<part;j++) {
{ lru pl;
cout<<mem[j]<<"\t"; clrscr();
} cout<<"\nlru in page replacements:";
i++; pl.getdata();
tm++; pl.replace();
} getch();
} }
while(i<len);

OPTIMAL PAGE REPLACEMENT {


mem[i]=pages[i];
#include<iostream.h>
count[pages[i]]--;
#include<stdlib.h>
pagefault++;
#include<conio.h>
}
class optimal
cout<<"\npages in memory:";
{
for(j=0;j<part;j++)
private:
{
int n,part,len,mem[20],pages[20],count[20];
cout<<mem[j]<<"\t";
int pagefault;
}
public:
tm=i;
void getdata();
do
void replace();
{
};
flag=0;
void optimal::getdata()
for(j=0;j<part;j++)
{
{
int i;
if(mem[j]==pages[i])
cout<<"\nenter no of partitions in memory:";
{
cin>>part;
flag=1;
cout<<"\nenter length of reference string:";
cunt[pages[i]]=count[pages[i]]-1;
cin>>len;
}
for(i=0;i<len;i++)
}
cin>>pages[i];
if(flag==1)
}
{
void optimal::replace()
cout<<"\npage exists in memory:";
{
i++;
int i,j,tm,flag,min,pos;
}
pagefault=0;
else
for(j=0;j<len;j++)
{
count[j]=0;
min=999;
for(j=0;j<len;j++)
for(j=0;j<part;j++)
{
{
count[pages[j]]=count[pages[j]]+1;
if(count[mem[j]]<min)
}
{
for(i=0;i<part;i++)
min=count[mem[j]];
pos=j; }
} while(i<len);
} cout<<"\nno of pagefaults:"<<pagefault<<"\n";
mem[pos]=pages[i]; }
count[pages[i]]=1; void main()
pagefault++; {
cout<<"\npages in memory:"; optimal p1;
for(j=0;j<part;j++) clrscr();
{ cout<<"\noptimal page replacement:";
cout<<mem[j]<<"\t"; p1.getdata();
} p1.replace();
i++; getch();
tm++; }
}

PAGING
#include<stdio.h>
#include<conio.h>
void main()
{
int i,arr[100],pagetable[20],val,pageno,offset,phymem,framesize;
int noframes;
clrscr();
printf("enter the physical memory:");
scanf("%d",&phymem);
for(i=1;i<=phymem;i++)
arr[i]=i;
printf("\nenter the size of the frame on page:");
scanf("%d",&framesize);
noframes=phymem/framesize;
printf("\nno of frames available are %d",noframes);
printf("\nenter \t frame\n");
for(i=1;i<=noframes;i++)
{
printf("\n%d\t\t",i);
scanf("\t\t\t%d",&pagetable[i]);
}
printf("\nenter the pageno:");
scanf("%d",&pageno);
printf("enter th offset");
scanf("%d",&offset);
val=(framesize*pagetable[pageno])+offset;
printf("\nthe physical address is %d",val);
getch();
}

You might also like