https://github.com/aftermath22/os-algorithms
C++ implementation (with OOPS concept) of various OS Algorithms
https://github.com/aftermath22/os-algorithms
cpp cpu-scheduling fit-algorithm object-oriented-programming oops-in-cpp operating-system os page-replacement-algorithm stl stl-algorithms
Last synced: 8 months ago
JSON representation
C++ implementation (with OOPS concept) of various OS Algorithms
- Host: GitHub
- URL: https://github.com/aftermath22/os-algorithms
- Owner: aftermath22
- License: mit
- Created: 2024-08-24T08:09:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-08T16:18:27.000Z (about 1 year ago)
- Last Synced: 2025-02-15T16:47:43.785Z (10 months ago)
- Topics: cpp, cpu-scheduling, fit-algorithm, object-oriented-programming, oops-in-cpp, operating-system, os, page-replacement-algorithm, stl, stl-algorithms
- Language: C++
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OS - ALGORITHMS
## CPU-Scheduling-Algorithms
1. First-Come, First-Served (FCFS):
**Description**: In FCFS, the processes are executed in the order they arrive in the ready queue. The first process that arrives is the first to be executed. \
**Advantages**: Simple and easy to implement. \
**Disadvantages**: Can lead to the "convoy effect," where shorter processes get stuck waiting behind longer ones, causing inefficiency.
Implementation : \

2. Round Robin (RR):
**Description**: In Round Robin, each process is assigned a fixed time slice or quantum. The CPU cycles through the processes, executing each for the time quantum, then moves to the next process in the queue. \
**Advantages**: Fairly distributes CPU time among all processes, reducing the chance of starvation. \
**Disadvantages**: Performance heavily depends on the length of the time quantum. If it's too short, the overhead of context switching can be high; if too long, it behaves more like FCFS.
Implmentation : \

3. Priority Scheduling (Non-preemptive):
**Description**: In Priority Scheduling, each process is assigned a priority, and the CPU is allocated to the process with the highest priority. In the non-preemptive version, the CPU will not be taken away from a running process even if a higher-priority process arrives. \
**Advantages**: Important tasks get executed first. \
**Disadvantages**: Can lead to starvation, where low-priority processes may never get executed if higher-priority processes keep arriving.
Implementation : \

4. Shortest Job First (SJF):
**Description**: In SJF, the process with the shortest burst time (execution time) is selected next. This minimizes the average waiting time in the queue. \
**Advantages**: Efficient in terms of reducing average waiting time. \
**Disadvantages**: Difficult to implement since it requires precise knowledge of the burst time of processes. Also, can lead to starvation of longer processes.
Implementation : \

## Page Replacement Algorithms
Page replacement algorithms are used in operating systems to decide which memory pages to replace when a new page is required in the page frame.
1. FIFO (First-In, First-Out)
Replaces the oldest page in the memory.
Advantages:
Simple and easy to implement.
Requires minimal tracking.
Disadvantages:
May lead to poor performance (Belady's Anomaly).
Ignores usage patterns of pages. \
Implementation: \

2. LRU (Least Recently Used)
Replaces the page that has not been used for the longest time.
Advantages:
Approximates optimal performance in many scenarios.
Adapts well to practical workloads.
Disadvantages:
Implementation overhead due to tracking usage history.
Performance may degrade with frequent context switches. \
Implementation: \

3. MRU (Most Recently Used)
Replaces the page that was most recently used.
Advantages:
Useful in specific workloads where recently used data becomes irrelevant.
Simpler to implement than LRU.
Disadvantages:
Poor performance for general workloads.
Rarely matches real-world access patterns. \
Implementation: \

4. OPTIMAL (Optimal Page Replacement)
Replaces the page that will not be used for the longest time in the future.
Advantages:
Provides the best theoretical performance.
Serves as a benchmark for other algorithms.
Disadvantages:
Requires future knowledge, which is impractical.
Used primarily for analysis and comparison. \
Implementation: \

## Fit Algorithms
Fit algorithms determine how memory blocks are allocated to processes based on their size requirements.
1. First Fit
Allocates the first available block that is large enough.
Advantages:
Simple and fast.
Reduces search time for allocation.
Disadvantages:
Causes external fragmentation.
Does not consider optimal utilization of space. \
2. Next Fit
Starts searching from the last allocated block and wraps around.
Advantages:
Similar speed to First Fit with improved locality.
Prevents clustering near the start of memory.
Disadvantages:
Suffers from fragmentation issues like First Fit. \
3. Best Fit
Allocates the smallest block that is large enough.
Advantages:
Reduces leftover space, minimizing fragmentation.
Optimizes memory usage.
Disadvantages:
Slower due to the need for scanning the entire list.
May create small unusable gaps. \
4. Worst Fit
Allocates the largest available block.
Advantages:
Avoids small leftover gaps.
Provides large contiguous space for future allocations.
Disadvantages:
Wastes memory by allocating unnecessarily large blocks.
May lead to more fragmentation. \
\
Fit Algorithm Implementation ( -1 indicates that the particular process has not been allocated any memory ) : \
\
