forked from sudikrt/assignments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfifo.c
52 lines (49 loc) · 1.81 KB
/
fifo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int n, k, i, count = 0, ref [20 ], f_size, frame_array [10] = {0}, j, hit = 0, pos = 0;
printf ("\tEnter the no. of elements :");
scanf ("%d", &n);
printf ("\tEnter the frame size:");
scanf ("%d", &f_size);
printf ("\tEnter the page no. :");
for (i = 0; i < n; i++)
{
scanf ("%d", &ref [i]);
}
for (i = 0; i < n; i++)
{
count = 0;
for ( j = 0; j < f_size; j++)
{
if (ref [i] == frame_array [j])
{
hit++;
count = 1;
printf ("\tHit in the Frame value of %d page is \t", ref [i]);
for (k = 0; k < f_size ; k++)
{
printf ("\t%d",frame_array [k]);
}
printf ("\n\n");
break;
}
}
if (count == 0){
if (pos >= f_size )
{
pos = 0;
}
frame_array [pos++] = ref [i];
printf ("\tFrame value is of %d page is \t", ref [i]);
for (k = 0; k < f_size ; k++)
{
printf ("\t%d",frame_array [k]);
}
printf ("\n\n");
}
}
printf ("Hit %d\n", hit);
printf ("Total no of page fault is %d\n", (n-hit));
}