Posts

Comparative Study - Simulation of Page Replacement Algorithms

  Comparative Simulation of Page Replacement Algorithms 1. Aim To simulate and compare the performance of: FIFO LRU LFU Random Optimal using a randomly generated page reference string with 3 page frames , and to calculate: Total Hits Total Misses Hit Rate 2. Objective To understand different page replacement strategies To compare performance of various algorithms To observe that Optimal gives minimum page faults To analyze hit rate differences 3. Theory When a process executes, pages are loaded into memory frames. If a page is not in memory, a page fault occurs. Different page replacement algorithms decide which page to remove when memory is full. Algorithms Used: 1️⃣ FIFO (First In First Out) Replaces the oldest page in memory. Simple queue-based approach. May suffer from Belady’s anomaly . 2️⃣ LRU (Least Recently Used) Replaces the page that has not been used for the longest time. Uses past reference inform...

Optimal Page Replacement Algorithm

  Optimal Page Replacement Algorithm 1. Aim To implement the Optimal Page Replacement Algorithm and display the frame contents after each page reference . 2. Objective To understand the working of the Optimal page replacement strategy To replace the page that will not be used for the longest time in the future To display the frame table after each page arrival To analyze page hits and page faults 3. Theory The Optimal Page Replacement Algorithm replaces the page that will not be used for the longest time in the future . Key Idea: “Replace the page whose next use is farthest in the future.” This algorithm produces the minimum possible number of page faults for a given reference string and number of frames. ⚠️ Note: Optimal replacement cannot be implemented in real operating systems because future page references are unknown. It is mainly used as a benchmark to compare other algorithms like FIFO and LRU. 4. Data Structures Used Structure Purpose fr...

Random Page Replacement Algorithm

  Random Page Replacement Algorithm 1. Aim To implement the Random Page Replacement Algorithm and display the frame contents after each page reference . 2. Objective To understand the working of Random page replacement To replace a page using a random selection strategy To display the frame table after each page arrival To analyze page hits and page faults To compare its behavior with FIFO, LRU, and Optimal 3. Theory The Random Page Replacement Algorithm replaces a page selected randomly from the available frames when a page fault occurs and no empty frame is available. 🔹 Key Idea: “When replacement is needed, choose any frame randomly.” Unlike: FIFO → replaces oldest page LRU → replaces least recently used page LFU → replaces least frequently used page Optimal → replaces page used farthest in future Random replacement does not consider past or future information . 4. Characteristics Feature         ...

First Come First Serve (FCFS) Disk Scheduling

  First Come First Serve (FCFS) Disk Scheduling Aim To implement the FCFS disk scheduling algorithm and compute the total head movement. Objective To understand how disk requests are serviced in arrival order To calculate total seek time and head movement To study performance compared with other algorithms Theory First Come First Serve (FCFS) is the simplest disk scheduling algorithm . In this method, the disk head services requests in the exact order they arrive in the queue. No reordering of requests Works like a normal queue (FIFO) Fair and easy to implement Working Principle Start from the initial head position. Move to the first request in the queue. Then move to the next request in sequence. Continue until all requests are completed. Seek Time Formula S e e k   T i m e = ∣ C u r r e n t   T r a c k − N e x t   T r a c k ∣ Seek\ Time = |Current\ Track - Next\ Track| T o t a l   H e a d   M o v e m e n t...

Shortest Seek Time First (SSTF) Disk Scheduling

  Shortest Seek Time First (SSTF) Disk Scheduling Aim To simulate the SSTF disk scheduling algorithm and compute the total head movement , displaying Step, From, To, Movement . Theory Shortest Seek Time First (SSTF) selects the disk request that is closest to the current head position . Minimizes immediate seek time Improves performance compared to FCFS May cause starvation for far-away requests Algorithm Read number of disk requests. Read request queue. Read initial head position. Mark all requests as unvisited. From current head: Find request with minimum absolute distance Move head to that request Add movement to total Mark request visited Repeat until all requests are serviced. Program: SSTF Disk Scheduling (C) # include <stdio.h> # include <stdlib.h> int main () { int n, head, total = 0 ; printf ( "Enter number of requests: " ); scanf ( "%d" , &n); int req[n], v...

SCAN Disk Scheduling Algorithm

  SCAN Disk Scheduling Algorithm Aim To simulate the SCAN disk scheduling algorithm and compute the total head movement , displaying Step, From, To, Movement . Theory The SCAN algorithm moves the disk head in one direction first , servicing all requests in its path until it reaches the end of the disk , then reverses direction and services remaining requests. Because the head sweeps back and forth like an elevator, SCAN is also called: 👉 Elevator Algorithm Advantages Better than FCFS in reducing seek time Avoids starvation seen in SSTF Provides more uniform waiting time Disadvantage Requests at extreme ends may wait longer Algorithm Read number of disk requests. Read request queue. Read initial head position. Read disk size. Read direction (LEFT or RIGHT). Sort request queue. If direction = RIGHT: Service all requests greater than head (ascending) Move to disk end Reverse and service remaining smaller requests If dire...