can someone give me any tips on how I can get three page frames for each process. Currently I have 1 frame for each.
#include<stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <time.h>
int prosCompleted=0;
struct Process
{
int ID;
int size;
int lifetime;
int remtime;
int start_time;
int finish_time;
int ref_str;
} L_pro[10], p;
struct CQueue
{
int head;
int tail;
int Values[10];
} Page_Frame;
int isFull()
{
if(Page_Frame.tail-Page_Frame.head >= 10)
return 1;
return 0;
}
void AddQ (int value)
{
if (isFull ())
RemoveQ();
Page_Frame.Values[Page_Frame.tail++]=value;
printf("%d\n", Page_Frame.tail-Page_Frame.head);
}
int RemoveQ (int value)
{
if(Page_Frame.head != Page_Frame.tail)
Page_Frame.Values[Page_Frame.head++]=value;
Page_Frame.Values[Page_Frame.tail++]=Page_Frame.Values[Page_Frame.head];
return Page_Frame.Values[Page_Frame.head++];
return -1;
}
void Init()
{
Page_Frame.head=0;
Page_Frame.tail=0;
}
int isPresent (int value)
{
int i=0;
for(i=Page_Frame.head; i<Page_Frame.tail; i++)
if(value == Page_Frame.Values[i])
return 1;
return 0;
}
void Display ()
{
prosCompleted++;
printf("Pr: ");
printf("%d", p.ID);
printf(" size: ");
printf("%d", p.size);
printf(" lifetime: ");
printf("%d", p.lifetime);
printf(" creation: ");
printf("%d", p.start_time);
printf(" completion: ");
printf("%d", p.finish_time);
printf(" Page Frame: ");
printf("%d", p.ref_str);
printf("\n");
}
int main()
{
int PageFaults=0, value=0, i, Rands[40], count=0;
static int ProcessNo=1, run =0;
Init();
srand(time(0));
for (i=0; i<40; i++)
{
value = rand()%20;
p.size = 4+rand()%35;
p.lifetime = 1+rand()%10;
p.remtime = p.lifetime;
p.start_time = run;
if (!isPresent(value))
{
printf("size: ");
printf("%d", p.size);
printf(" lifetime: ");
printf("%d", p.lifetime);
printf(" creation: ");
printf("%d", p.start_time);
printf(" completion: ");
printf("%d", p.finish_time);
printf(" recieves Page Frame ");
PageFaults++;
AddQ(value);
printf("\t");
}
Rands[count++]=value;
}
printf("\n\nThere were ");
printf("%d", PageFaults);
printf(" Page Faults\n\nReference String:\n\n");
for(i=0; i<40; i++)
{
printf("%d", Rands[i]);
printf("\t");
}
getch();
}