-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFIFO_Page_Replacement.py
52 lines (43 loc) · 1.48 KB
/
FIFO_Page_Replacement.py
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
frames=int(input("Please enter the number of Page frames: "))
length=int(input("Enter the length of reference String: "))
string=[]
page_frame=[]
for i in range(length):
no=int(input("Please enter the {0} character of the reference string: ".format(i+1,{0})))
string.append(no)
print("The entered reference string is ",string)
#initailizing none values for page frames
for i in range(frames):
page_frame.append(None)
print("Here, None refers that the page frame in empty")
First_in=0
page_hit=0
continue_outer_loop=False
for i in string:
for j in page_frame:
if j==i:
page_hit=page_hit+1
continue_outer_loop=True
#continue if element already in page frame
if continue_outer_loop:
continue_outer_loop=False
print(i," already in memory no fault for this reference")
continue
else:
#replacing intial none or empty frames
if None in page_frame:
for k in page_frame:
if k==None:
page_frame[page_frame.index(k)]=i
break
else:
page_frame[First_in]=i
#get the top element to remove
if First_in==(frames-1):
First_in=0
else:
First_in=First_in+1
print("Page Frame: ",page_frame," for reference: ",i )
#calculate page faults
page_fault=len(string)-page_hit
print("Page fault : ",page_fault)