-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtual Memory Simulation App.py
More file actions
100 lines (74 loc) · 2.75 KB
/
Virtual Memory Simulation App.py
File metadata and controls
100 lines (74 loc) · 2.75 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import tkinter as tk
from tkinter import messagebox
def fifo_simulation(pages, frames_count):
frames = []
page_faults = 0
result = []
for page in pages:
if page not in frames:
page_faults += 1
if len(frames) < frames_count:
frames.append(page)
else:
frames.pop(0)
frames.append(page)
result.append(frames.copy())
return result, page_faults
def lru_simulation(pages, frames_count):
frames = []
page_faults = 0
recent = []
result = []
for page in pages:
if page not in frames:
page_faults += 1
if len(frames) < frames_count:
frames.append(page)
else:
lru_page = recent.pop(0)
frames.remove(lru_page)
frames.append(page)
else:
recent.remove(page)
recent.append(page)
result.append(frames.copy())
return result, page_faults
def simulate():
pages_input = entry_pages.get().strip()
frames_input = entry_frames.get().strip()
if not pages_input or not frames_input:
messagebox.showerror("Input Error", "Please enter pages and frame count.")
return
pages = pages_input.split(",")
frames_count = int(frames_input)
algorithm = algo_var.get()
if algorithm == "FIFO":
result, faults = fifo_simulation(pages, frames_count)
else:
result, faults = lru_simulation(pages, frames_count)
output_text.delete("1.0", tk.END)
output_text.insert(tk.END, f"Algorithm: {algorithm}\n")
output_text.insert(tk.END, f"Frames: {frames_count}\n\n")
for i, state in enumerate(result):
output_text.insert(tk.END, f"Step {i+1}: {state}\n")
output_text.insert(tk.END, f"\nTotal Page Faults: {faults}\n")
# GUI Setup
root = tk.Tk()
root.title("Virtual Memory Simulation App")
root.geometry("700x500")
title_label = tk.Label(root, text="Virtual Memory Simulation", font=("Arial", 16, "bold"))
title_label.pack(pady=10)
tk.Label(root, text="Enter Page Reference String (comma-separated):").pack()
entry_pages = tk.Entry(root, width=60)
entry_pages.pack(pady=5)
tk.Label(root, text="Enter Number of Frames:").pack()
entry_frames = tk.Entry(root, width=10)
entry_frames.pack(pady=5)
algo_var = tk.StringVar(value="FIFO")
tk.Radiobutton(root, text="FIFO", variable=algo_var, value="FIFO").pack()
tk.Radiobutton(root, text="LRU", variable=algo_var, value="LRU").pack()
simulate_button = tk.Button(root, text="Simulate", command=simulate)
simulate_button.pack(pady=10)
output_text = tk.Text(root, height=15, width=80)
output_text.pack(pady=10)
root.mainloop()