Created
January 2, 2022 09:18
-
-
Save rudSarkar/f2a15cdef16b189d031dc82fc0534b4c to your computer and use it in GitHub Desktop.
FIFO Page Replacement Algorithm
This file contains hidden or 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
echo "Enter the number of Pages: \t" | |
read PAGES | |
echo "Enter reference string values: \n" | |
for ((m = 0; m < PAGES; m++)); do | |
echo "Page $m \t" | |
read ref[$m] | |
done | |
echo "What are the total number of frames: \t" | |
read FRAMES | |
temp[$FRAMES]="" | |
for ((m = 0; m < FRAMES; m++)); do | |
temp[$m]="-1" | |
done | |
for ((m = 0; m < PAGES; m++)); do | |
s=0 | |
for ((n = 0; n < FRAMES; n++)); do | |
if [ "${ref[$m]}" == "${temp[$n]}" ]; then | |
let s++ | |
let pageFault++ | |
fi | |
done | |
let pageFault++ | |
if [[ $pageFault -ge $FRAMES ]] && [[ $s -eq 0 ]]; then | |
let $((temp[m] = ref[m])) | |
elif [[ $s -eq 0 ]]; then | |
let $((temp[(pageFault - 1) % FRAMES] = ref[m])) | |
fi | |
echo "\n" | |
for ((n = 0; n < FRAMES; n++)); do | |
echo "${temp[$n]}\t" | |
done | |
done | |
echo "\nPage Fault: \t$pageFault\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment