{"id":23447250,"url":"https://github.com/aftermath22/os-algorithms","last_synced_at":"2025-04-10T01:19:25.806Z","repository":{"id":254553568,"uuid":"846883199","full_name":"aftermath22/OS-ALGORITHMS","owner":"aftermath22","description":"C++ implementation (with OOPS concept) of various OS Algorithms","archived":false,"fork":false,"pushed_at":"2024-12-08T16:18:27.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T16:47:43.785Z","etag":null,"topics":["cpp","cpu-scheduling","fit-algorithm","object-oriented-programming","oops-in-cpp","operating-system","os","page-replacement-algorithm","stl","stl-algorithms"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aftermath22.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-24T08:09:02.000Z","updated_at":"2024-12-14T19:23:25.000Z","dependencies_parsed_at":"2024-08-24T09:45:20.201Z","dependency_job_id":"135b0ca5-3083-44e9-946a-3539965cc8e1","html_url":"https://github.com/aftermath22/OS-ALGORITHMS","commit_stats":null,"previous_names":["aftermath22/cpu-scheduling-algorithms","aftermath22/os-algorithms"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOS-ALGORITHMS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOS-ALGORITHMS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOS-ALGORITHMS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aftermath22%2FOS-ALGORITHMS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aftermath22","download_url":"https://codeload.github.com/aftermath22/OS-ALGORITHMS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137959,"owners_count":21053788,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpu-scheduling","fit-algorithm","object-oriented-programming","oops-in-cpp","operating-system","os","page-replacement-algorithm","stl","stl-algorithms"],"created_at":"2024-12-23T21:17:03.183Z","updated_at":"2025-04-10T01:19:25.780Z","avatar_url":"https://github.com/aftermath22.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OS - ALGORITHMS\n## CPU-Scheduling-Algorithms\n1. First-Come, First-Served (FCFS):\n\n**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. \\\n**Advantages**: Simple and easy to implement. \\\n**Disadvantages**: Can lead to the \"convoy effect,\" where shorter processes get stuck waiting behind longer ones, causing inefficiency. \n\nImplementation : \\\n![WhatsApp Image 2024-08-28 at 23 45 51_b105b1ec](https://github.com/user-attachments/assets/34b94b88-10ba-422c-84b1-57822709db6a)\n\n\n\n\n2. Round Robin (RR):\n\n**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. \\\n**Advantages**: Fairly distributes CPU time among all processes, reducing the chance of starvation. \\\n**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. \n\nImplmentation : \\\n![WhatsApp Image 2024-08-28 at 23 45 51_e503d1cd](https://github.com/user-attachments/assets/3c95963a-1625-4079-9aff-229555880b07)\n\n\n3. Priority Scheduling (Non-preemptive):\n\n**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. \\\n**Advantages**: Important tasks get executed first. \\\n**Disadvantages**: Can lead to starvation, where low-priority processes may never get executed if higher-priority processes keep arriving. \n\nImplementation : \\\n![WhatsApp Image 2024-08-28 at 23 45 51_4cba662c](https://github.com/user-attachments/assets/5f9427fb-053c-4ca2-aac1-53098a42bab7)\n\n\n\n4. Shortest Job First (SJF):\n\n**Description**: In SJF, the process with the shortest burst time (execution time) is selected next. This minimizes the average waiting time in the queue. \\\n**Advantages**: Efficient in terms of reducing average waiting time. \\\n**Disadvantages**: Difficult to implement since it requires precise knowledge of the burst time of processes. Also, can lead to starvation of longer processes. \n\nImplementation : \\\n![WhatsApp Image 2024-08-28 at 23 45 51_b0a4edf1](https://github.com/user-attachments/assets/772910c4-1c8f-49f2-8739-58b8fa8a3781)\n\n## Page Replacement Algorithms\nPage replacement algorithms are used in operating systems to decide which memory pages to replace when a new page is required in the page frame. \n\n1. FIFO (First-In, First-Out)\nReplaces the oldest page in the memory.\n\nAdvantages:\n\nSimple and easy to implement.\nRequires minimal tracking.\nDisadvantages:\n\nMay lead to poor performance (Belady's Anomaly).\nIgnores usage patterns of pages. \\\nImplementation: \\\n![image](https://github.com/user-attachments/assets/4b2b663b-b479-4b45-8b83-ec01a274be7f)\n\n\n2. LRU (Least Recently Used)\nReplaces the page that has not been used for the longest time.\n\nAdvantages:\n\nApproximates optimal performance in many scenarios.\nAdapts well to practical workloads.\nDisadvantages:\n\nImplementation overhead due to tracking usage history.\nPerformance may degrade with frequent context switches. \\\nImplementation: \\\n![image](https://github.com/user-attachments/assets/93ab57bd-1ff4-417d-91ed-c05d40d2ccf1)\n\n\n3. MRU (Most Recently Used)\nReplaces the page that was most recently used.\n\nAdvantages:\n\nUseful in specific workloads where recently used data becomes irrelevant.\nSimpler to implement than LRU.\nDisadvantages:\n\nPoor performance for general workloads.\nRarely matches real-world access patterns. \\\nImplementation: \\\n![image](https://github.com/user-attachments/assets/dc5b2349-33a7-4ddd-9151-ad7925eac30f)\n\n\n4. OPTIMAL (Optimal Page Replacement)\nReplaces the page that will not be used for the longest time in the future.\n\nAdvantages:\n\nProvides the best theoretical performance.\nServes as a benchmark for other algorithms.\nDisadvantages:\n\nRequires future knowledge, which is impractical.\nUsed primarily for analysis and comparison. \\\nImplementation: \\\n![image](https://github.com/user-attachments/assets/8cfac73e-8cb3-4f27-bb57-3b615394d89b)\n\n\n## Fit Algorithms\nFit algorithms determine how memory blocks are allocated to processes based on their size requirements.\n\n1. First Fit\nAllocates the first available block that is large enough.\n\nAdvantages:\n\nSimple and fast.\nReduces search time for allocation.\nDisadvantages:\n\nCauses external fragmentation.\nDoes not consider optimal utilization of space. \\\n\n2. Next Fit\nStarts searching from the last allocated block and wraps around.\n\nAdvantages:\n\nSimilar speed to First Fit with improved locality.\nPrevents clustering near the start of memory.\nDisadvantages:\n\nSuffers from fragmentation issues like First Fit. \\\n\n3. Best Fit\nAllocates the smallest block that is large enough.\n\nAdvantages:\n\nReduces leftover space, minimizing fragmentation.\nOptimizes memory usage.\nDisadvantages:\n\nSlower due to the need for scanning the entire list.\nMay create small unusable gaps. \\\n\n4. Worst Fit\nAllocates the largest available block.\n\nAdvantages:\n\nAvoids small leftover gaps.\nProvides large contiguous space for future allocations.\nDisadvantages:\n\nWastes memory by allocating unnecessarily large blocks.\nMay lead to more fragmentation. \\\n\\\nFit Algorithm Implementation ( -1 indicates that the particular process has not been allocated any memory ) : \\\n\\\n![image](https://github.com/user-attachments/assets/1d32fd27-1915-4ee4-bc7a-442b1d6b4f5b)\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftermath22%2Fos-algorithms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faftermath22%2Fos-algorithms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faftermath22%2Fos-algorithms/lists"}