Posts

Showing posts from September, 2025

Deadlock-Free Solution to Dining Philosophers Problem Using Semaphores

  Deadlock-Free Solution to Dining Philosophers Problem Using Semaphores 1. Aim To implement a deadlock-free solution for the Dining Philosophers Problem using semaphores . 2. Objective To study process synchronization To avoid deadlock and race conditions To ensure mutual exclusion using semaphores 3. Problem Statement Five philosophers sit around a circular table. Each philosopher alternates between thinking and eating . To eat, a philosopher must acquire both left and right chopsticks . The challenge is to design a solution that: Avoids deadlock Avoids race condition Allows maximum parallelism 4. Theory Why Deadlock Occurs (Naive Solution) If all philosophers pick up their left chopstick first , a circular wait occurs → deadlock . Deadlock-Free Strategy Used We use a binary semaphore room that allows only 4 philosophers to try picking chopsticks at the same time. This breaks circular wait , one of the four deadlock conditions. 5...

FIFO Page Replacement Algorithm

  FIFO Page Replacement Algorithm  1. Aim To simulate the FIFO page replacement algorithm and display the frame contents in a tabular form for each page reference. 2. Objective To understand FIFO page replacement To observe page hits and faults To display memory frame status step-by-step 3. Theory  3.1 Virtual Memory Virtual memory allows execution of processes larger than physical memory by dividing memory into pages . When a required page is not in memory , a page fault occurs and the OS must replace an existing page. 3.2 FIFO Page Replacement Algorithm FIFO (First-In First-Out) replaces the page that entered memory earliest , irrespective of how frequently or recently it was used. ➡ Conceptually simple but may suffer from Belady’s anomaly . 3.3 Key Characteristics Feature                Description Replacement policy                   ...

Least Recently Used (LRU) Page Replacement Algorithm

  Least Recently Used (LRU) Page Replacement Algorithm 1. Aim To implement the Least Recently Used (LRU) Page Replacement Algorithm and display the frame contents after each page arrival . 2. Objective To understand how LRU selects a victim page To implement LRU using time (recency) tracking To analyze page hits and page faults 3. Theory The LRU algorithm replaces the page that has not been used for the longest time in the past. Key Idea: “The page that was least recently accessed is least likely to be used again.” LRU approximates optimal behavior better than FIFO but requires tracking past usage . 4. Data Structures Used Structure Purpose frames[]                     Stores pages in memory time[]                     Stores last-used time of each frame counter                   ...

Least Frequently Used (LFU) Page Replacement Algorithm

  Least Frequently Used (LFU) Page Replacement Algorithm 1. Aim To implement the Least Frequently Used (LFU) Page Replacement Algorithm and display the frame contents after each page reference . 2. Objective To understand the working of LFU page replacement To replace the page with the minimum access frequency To analyze page hits and page faults 3. Theory The LFU algorithm replaces the page that has been used least often . Key Idea: “Pages with low access frequency are less likely to be used again.” When two pages have the same frequency, FIFO order (or oldest) is commonly used as a tie-breaker. 4. Data Structures Used Structure Purpose frames[]                Stores pages in memory freq[]                Stores access frequency time[]                Stores arrival time (tie-breaker) counter       ...

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...