|
| 1 | +# CPU Scheduling Algorithms Project Documentation |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | +- [Introduction](#introduction) |
| 6 | +- [Implemented Algorithms](#implemented-algorithms) |
| 7 | +- [Project Structure](#project-structure) |
| 8 | +- [Installation](#installation) |
| 9 | +- [Input Format](#input-format) |
| 10 | +- [Usage](#usage) |
| 11 | +- [Testing](#testing) |
| 12 | +- [Algorithm Details](#algorithm-details) |
| 13 | +- [Extending the Project](#extending-the-project) |
| 14 | +- [References](#references) |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Introduction |
| 19 | + |
| 20 | +This project implements various CPU scheduling algorithms in C++. It is designed to simulate and analyze the behavior of different scheduling strategies, providing both trace and statistical outputs. The project is suitable for educational purposes, operating systems coursework, and performance analysis. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Implemented Algorithms |
| 25 | + |
| 26 | +1. **FCFS (First Come First Serve)** |
| 27 | +2. **RR (Round Robin)** |
| 28 | +3. **SPN (Shortest Process Next)** |
| 29 | +4. **SRT (Shortest Remaining Time)** |
| 30 | +5. **HRRN (Highest Response Ratio Next)** |
| 31 | +6. **FB-1 (Feedback, all queues q=1)** |
| 32 | +7. **FB-2i (Feedback, q=2^i)** |
| 33 | +8. **Aging** |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Project Structure |
| 38 | + |
| 39 | +``` |
| 40 | +CPU-Scheduling-Algorithms-main/ |
| 41 | +├── src/ # Source code for algorithms and main program |
| 42 | +├── include/ # Header files |
| 43 | +├── test/ # Unit tests (Google Test) |
| 44 | +├── docs/ # Documentation |
| 45 | +├── makefile # Build instructions |
| 46 | +├── README.md # Project overview and quick start |
| 47 | +└── run.sh # Shell script to build and run the project |
| 48 | +``` |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Installation |
| 53 | + |
| 54 | +1. **Clone the repository:** |
| 55 | + ```sh |
| 56 | + git clone <repository-url> |
| 57 | + cd CPU-Scheduling-Algorithms-main |
| 58 | + ``` |
| 59 | + |
| 60 | +2. **Install dependencies:** |
| 61 | + ```sh |
| 62 | + sudo apt-get update |
| 63 | + sudo apt-get install -y g++ make libgtest-dev cmake |
| 64 | + ``` |
| 65 | + |
| 66 | +3. **Build the project:** |
| 67 | + ```sh |
| 68 | + make |
| 69 | + ``` |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Input Format |
| 74 | + |
| 75 | +- **Line 1:** `"trace"` or `"stats"` (output mode) |
| 76 | +- **Line 2:** Comma-separated list of scheduling policies and parameters (e.g., `1,2-4,8-1`) |
| 77 | +- **Line 3:** Integer specifying the last instant for simulation |
| 78 | +- **Line 4:** Integer specifying the number of processes |
| 79 | +- **Line 5+:** Process descriptions (one per line) |
| 80 | + |
| 81 | +### Process Description |
| 82 | + |
| 83 | +- **Algorithms 1-7:** |
| 84 | + ``` |
| 85 | + <ProcessName>,<ArrivalTime>,<ServiceTime> |
| 86 | + ``` |
| 87 | +- **Algorithm 8 (Aging):** |
| 88 | + ``` |
| 89 | + <ProcessName>,<ArrivalTime>,<Priority> |
| 90 | + ``` |
| 91 | + |
| 92 | +**Note:** |
| 93 | +Processes must be sorted by arrival time. If two processes have the same arrival time, the one with the lower priority arrives first. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## Usage |
| 98 | + |
| 99 | +1. **Compile the project:** |
| 100 | + ```sh |
| 101 | + make |
| 102 | + ``` |
| 103 | + |
| 104 | +2. **Run the main executable:** |
| 105 | + ```sh |
| 106 | + ./main < input.txt |
| 107 | + ``` |
| 108 | + |
| 109 | + Replace `input.txt` with your input file following the [Input Format](#input-format). |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## Testing |
| 114 | + |
| 115 | +Unit tests are provided using Google Test. |
| 116 | + |
| 117 | +- **Build and run tests:** |
| 118 | + ```sh |
| 119 | + make test |
| 120 | + ./test/hello_gtest |
| 121 | + ``` |
| 122 | + |
| 123 | +- **Automated testing:** |
| 124 | + GitHub Actions is configured to run tests on every push and pull request. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## Algorithm Details |
| 129 | + |
| 130 | +### 1. FCFS (First Come First Serve) |
| 131 | +- Non-preemptive. |
| 132 | +- Processes are executed in the order they arrive. |
| 133 | + |
| 134 | +### 2. RR (Round Robin) |
| 135 | +- Preemptive. |
| 136 | +- Each process gets a fixed time quantum in a cyclic order. |
| 137 | + |
| 138 | +### 3. SPN (Shortest Process Next) |
| 139 | +- Non-preemptive. |
| 140 | +- Selects the process with the shortest service time. |
| 141 | + |
| 142 | +### 4. SRT (Shortest Remaining Time) |
| 143 | +- Preemptive version of SPN. |
| 144 | +- Always runs the process with the shortest remaining time. |
| 145 | + |
| 146 | +### 5. HRRN (Highest Response Ratio Next) |
| 147 | +- Non-preemptive. |
| 148 | +- Chooses the process with the highest response ratio. |
| 149 | + |
| 150 | +### 6. FB-1 (Feedback, q=1) |
| 151 | +- Preemptive. |
| 152 | +- Multiple queues, all with quantum 1. |
| 153 | + |
| 154 | +### 7. FB-2i (Feedback, q=2^i) |
| 155 | +- Preemptive. |
| 156 | +- Multiple queues, quantum doubles at each lower priority. |
| 157 | + |
| 158 | +### 8. Aging |
| 159 | +- Preemptive. |
| 160 | +- Priorities of waiting processes increase over time to prevent starvation. |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## Extending the Project |
| 165 | + |
| 166 | +- Add new scheduling algorithms by creating new source files in `src/` and updating the main driver. |
| 167 | +- Add new tests in `test/` using Google Test. |
| 168 | +- Update the makefile as needed. |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## References |
| 173 | + |
| 174 | +- [Operating System Concepts by Silberschatz, Galvin, Gagne](https://www.os-book.com/) |
| 175 | +- [Wikipedia: Scheduling (computing)](https://en.wikipedia.org/wiki/Scheduling_(computing)) |
| 176 | +- |
0 commit comments