Skip to content

Instantly share code, notes, and snippets.

@rudSarkar
Created January 2, 2022 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudSarkar/f2a15cdef16b189d031dc82fc0534b4c to your computer and use it in GitHub Desktop.
Save rudSarkar/f2a15cdef16b189d031dc82fc0534b4c to your computer and use it in GitHub Desktop.
FIFO Page Replacement Algorithm
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