-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain2.cpp
169 lines (147 loc) · 3.22 KB
/
main2.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
If you find any mistakes in this file
please let me know, so I can fix them and reupload
fixed version for everyone.
*/
#include "SimulatedOS.h"
int main()
{
SimulatedOS osSim{ 1, 300, 100 };
osSim.NewProcess(10);
osSim.NewProcess(5);
osSim.PrintRAM();
// Frame Page PID
// 0 0 1
// 1 0 2
// 2
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.FetchFrom(120);
osSim.PrintRAM();
// Frame Page PID
// 0 0 1
// 1 0 2
// 2 1 1
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.DiskReadRequested(0, "job.docx");
osSim.PrintRAM();
// Frame Page PID
// 0 0 1
// 1 0 2
// 2 1 1
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.FetchFrom(777);
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1 0 2
// 2 1 1
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.NewProcess(1);
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1 0 2
// 2 0 3
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.DiskJobCompleted(0);
// The following happens after this command:
// The process 1 returns to ready-queue after the hard disk finished reading file for it.
// Since the process 1 has the higher priority than the one currently running, the process 1 starts using the CPU immedeately
// To use the CPU, the process one need its last used page (page 1) in memory (and thats what your simulation should provide)
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1 1 1
// 2 0 3
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.Exit();
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1
// 2 0 3
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.FetchFrom(740);
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1
// 2 0 3
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.FetchFrom(3350);
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1 33 2
// 2 0 3
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.FetchFrom(740);
// The page 7 of the process 2 is already in memory. RAM snapshot doesn't change but
// your simulation remembers that the page 7 is now freshly used.
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1 33 2
// 2 0 3
//std::cout<<"LRU "<<std::endl;
//osSim.printLRU();
osSim.NewProcess(20);
osSim.FetchFrom(100);
osSim.PrintRAM();
// Frame Page PID
// 0 7 2
// 1 1 4
// 2 0 4
return 0;
}
/*
int main()
{
//std::cout<<"I "<<std::endl;
SimulatedOS osSim{3, 96, 32};
//std::cout<<" i am here"<<std::endl;
osSim.NewProcess(4);
osSim.NewProcess(2);
osSim.NewProcess(7);
osSim.PrintCPU();
// CPU: 3
osSim.PrintReadyQueue();
//Ready-Queue: 1 2
osSim.DiskReadRequested(0, "HW.txt");
osSim.PrintCPU();
// CPU: 1
osSim.PrintDisk(0);
// Disk 0: PID 3, "HW.txt"
osSim.PrintDiskQueue(0);
// Disk 0 I/O-queue: Empty
osSim.PrintDiskQueue(5);
// Instruction ignored: no disk with such number exists
osSim.DiskJobCompleted(0);
osSim.PrintCPU();
// CPU: 3
osSim.PrintDisk(0);
// Disk 0: Idle
osSim.FetchFrom(48);
osSim.PrintRAM();
// Frame Page PID
// 0 0 1
// 1 1 3
// 2 0 3
osSim.Exit();
osSim.PrintCPU();
// CPU: 1
osSim.PrintRAM();
// Frame Page PID
// 0 0 1
return 0;
}
*/