-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5360d6d
commit e0c003f
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//This Source file is written by Nikita Rath (18BLC1131) | ||
clear; | ||
exec("F:\APP MAIN\Scilab\Ex_9_8_lru.sci") | ||
exec("F:\APP MAIN\Scilab\Ex_9_8_fifo.sci") | ||
exec("F:\APP MAIN\Scilab\Ex_9_8_optimal.sci") | ||
clc; | ||
|
||
//MAIN: (Given Conditions) | ||
printf("\n Given Page Reference String :\n \t") | ||
n = 20 | ||
a = [1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6] | ||
for i = 1:n | ||
printf("%d ",a(i)) | ||
end | ||
|
||
printf("\n\n 1) LRU replacement :\n\n") | ||
lru(a,n) | ||
|
||
printf("\n 2) FIFO replacement :\n\n") | ||
fifo(a,n) | ||
|
||
printf("\n 3) Optimal replacement :\n\n") | ||
op(a,n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//This Source file is written by Nikita Rath (18BLC1131) | ||
//FUNCTION FOR FIFO | ||
function [] = fifo(a,n) | ||
printf("\tNo. of Frames \t FIFO") | ||
x = 1 | ||
//for frames 1 to 7 | ||
while(x < 8) | ||
counter = 0 | ||
faults = 0 | ||
//Intialise all frames to -1 | ||
for i = 1:x | ||
frames(i) = -1 | ||
end | ||
flag1 = 1 | ||
//Traversing through pages | ||
for i = 1:n | ||
counter = 0 | ||
//Traversing through frames | ||
for k = 1:x | ||
//Page available in frame | ||
if(frames(k) == a(i)) then | ||
counter = counter + 1 | ||
end | ||
end | ||
//Page unavailable in frame | ||
if(counter == 0) then | ||
//First in page gets replaced first in frame | ||
frames(flag1+1) = a(i) | ||
flag1 = modulo((flag1+1),x) | ||
//Increment page faults | ||
faults = faults + 1 | ||
end | ||
end | ||
//Total page faults | ||
printf("\n\t\t %d \t %d ", x, faults) | ||
x = x + 1 | ||
end | ||
printf("\n") | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//This Source file is written by Nikita Rath (18BLC1131) | ||
//FUNCTION FOR LRU | ||
function [] = lru(a,n) | ||
printf("\tNo. of Frames \t LRU") | ||
x = 1 | ||
//for frames 1 to 7 | ||
while(x < 8) | ||
counter = 0 | ||
faults = 0 | ||
//Intialise all frames to -1 | ||
for i = 1:x | ||
frames(i) = -1 | ||
end | ||
//Traversing through pages | ||
for i = 1:n | ||
flag1 = 0 | ||
flag2 = 0 | ||
//Traversing through frames | ||
for j = 1:x | ||
//Page available in frame | ||
if(frames(j) == a(i)) then | ||
counter = counter + 1 | ||
temp(j) = counter | ||
//Set flag1 and flag2 | ||
flag1 = 1 | ||
flag2 = 1 | ||
break | ||
end | ||
end | ||
//Page unavailable in frame | ||
if(flag1 == 0) then | ||
//Traversing through frames | ||
for j = 1:x | ||
//Frame has empty space | ||
if(frames(j) == -1) then | ||
counter = counter + 1 | ||
//Increment page faults | ||
faults = faults + 1 | ||
frames(j) = a(i) | ||
temp(j) = counter | ||
flag2 = 1 | ||
break | ||
end | ||
end | ||
end | ||
//Page unavailable in frame | ||
if(flag2 == 0) then | ||
minimum = temp(1) | ||
pos = 1 | ||
//Traversing through frames | ||
for k = 2:x | ||
//Find least recently used page | ||
if(temp(k) < minimum) then | ||
minimum = temp(k) | ||
pos = k | ||
end | ||
end | ||
counter = counter + 1 | ||
//Increment page faults | ||
faults = faults + 1 | ||
frames(pos) = a(i) | ||
temp(pos) = counter | ||
end | ||
end | ||
//Total page faults | ||
printf("\n\t\t %d \t %d ", x, faults) | ||
x = x + 1 | ||
end | ||
printf("\n") | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//This Source file is written by Nikita Rath (18BLC1131) | ||
//FUNCTION FOR OPTIMAL | ||
function [] = op(a,n) | ||
printf("\tNo. of Frames \t Optimal") | ||
x = 1 | ||
//for frames 1 to 7 | ||
while(x < 8) | ||
counter = 0 | ||
faults = 0 | ||
//Intialise all frames to -1 | ||
for i = 1:x | ||
frames(i) = -1 | ||
end | ||
//Traversing through pages | ||
for i = 1:n | ||
flag1 = 0 | ||
flag2 = 0 | ||
//Traversing through frames | ||
for j = 1:x | ||
//Page available in frame | ||
if(frames(j) == a(i)) then | ||
//Set flag1 and flag2 | ||
flag1 = 1 | ||
flag2 = 1 | ||
break | ||
end | ||
end | ||
//Page unavailable in frame | ||
if(flag1 == 0) then | ||
//Traversing through frames | ||
for j = 1:x | ||
//Frame has empty space | ||
if(frames(j) == -1) then | ||
//Increment page faults | ||
faults = faults + 1 | ||
frames(j) = a(i) | ||
flag2 = 1 | ||
break | ||
end | ||
end | ||
end | ||
//Page unavailable in frame | ||
if(flag2 == 0) then | ||
flag3 =0 | ||
//Traversing through frames | ||
for j = 1:x | ||
temp(j) = -1 | ||
//Traversing through future pages | ||
for k = i+1:n | ||
//Page currently in frame available in future pages | ||
if(frames(j) == a(k)) then | ||
temp(j) = k | ||
break | ||
end | ||
end | ||
end | ||
//Traversing through frames | ||
for j = 1:x | ||
//page currently in frame unavailable in future pages | ||
if(temp(j) == -1) then | ||
pos = j | ||
//Set flag3 | ||
flag3 = 1 | ||
break | ||
end | ||
end | ||
//Page currently in frame available in future pages | ||
if(flag3 ==0) then | ||
maximum = temp(1) | ||
pos = 1 | ||
//Traversing through frames | ||
for j = 2:x | ||
//Find page in frame which is farther in future pages | ||
if(temp(j) > maximum) then | ||
maximum = temp(j) | ||
pos = j | ||
end | ||
end | ||
end | ||
frames(pos) = a(i) | ||
//Increment page faults | ||
faults = faults + 1 | ||
end | ||
end | ||
//Total page faults | ||
printf("\n\t\t %d \t %d ", x, faults) | ||
x = x + 1 | ||
end | ||
printf("\n") | ||
endfunction |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.