https://github.com/adolbyb/process-scheduler
A C++ process scheduler project using predefined processes and queue structs
https://github.com/adolbyb/process-scheduler
c-plus-plus cpp fcfs-scheduling mlfq-scheduling process-scheduler process-scheduling-algorithms queue sjf-scheduling struct
Last synced: 1 day ago
JSON representation
A C++ process scheduler project using predefined processes and queue structs
- Host: GitHub
- URL: https://github.com/adolbyb/process-scheduler
- Owner: ADolbyB
- License: gpl-3.0
- Created: 2021-12-29T16:02:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-01-31T15:58:08.000Z (6 months ago)
- Last Synced: 2026-02-01T03:37:26.154Z (6 months ago)
- Topics: c-plus-plus, cpp, fcfs-scheduling, mlfq-scheduling, process-scheduler, process-scheduling-algorithms, queue, sjf-scheduling, struct
- Language: C++
- Homepage:
- Size: 984 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CPU Process Scheduler
### Operating Systems Scheduling Algorithm Implementation
[](https://github.com/ADolbyB/process-scheduler/stargazers)
[](https://github.com/ADolbyB/process-scheduler/network/members)
[](https://github.com/ADolbyB/process-scheduler/actions/workflows/build-release.yml)
[](https://github.com/ADolbyB/process-scheduler/commits/main)
**Operating Systems Course Project - Grade: 98/100**
[](https://isocpp.org/)
[](https://www.linux.org/)
[](http://www.codeblocks.org/)
**Developed by:** [](https://github.com/ADolbyB)
---
## ๐ฏ Project Overview
A comprehensive **CPU process scheduling simulator** implementing three fundamental operating system scheduling algorithms. This project demonstrates core OS concepts including process management, queue data structures, CPU burst scheduling, and I/O handling using predefined process workloads.
**Key Features:**
- โ
Three distinct scheduling algorithms (FCFS, SJF, MLFQ)
- โ
Custom queue implementations for process management
- โ
Realistic CPU and I/O burst simulation
- โ
Performance metrics and visualization
- โ
GDB debugging support
---
## ๐ Academic Achievement
**Course:** Operating Systems
**Institution:** Florida Atlantic University
**Semester:** Fall 2021
**Final Grade:** **98/100**
This project earned near-perfect marks for implementing complex scheduling algorithms with clean, efficient C++ code and proper data structure design.
---
## ๐ Scheduling Algorithms Implemented
### 1. FCFS - First Come First Served
**Algorithm Type:** Non-preemptive
**Description:**
- Single Ready Queue and single I/O Queue
- Processes execute in order of arrival
- Each process runs until CPU burst completion
- Simple but can suffer from convoy effect
- Worst case scenario benchmark for average total wait time `T_w`
**Characteristics:**
- No process starvation
- Low scheduling overhead
- Poor average waiting time for short processes
- Ideal for batch processing systems
**Queue Structure:**
```
Ready Queue: [P1] โ [P2] โ [P3] โ [P4]
โ (CPU Burst Complete)
I/O Queue: [P1] โ [P2] โ ...
```
---
### 2. SJF - Shortest Job First
**Algorithm Type:** Non-preemptive
**Description:**
- Single Ready Queue and single I/O Queue
- Processes ordered by shortest CPU burst time
- Minimizes average waiting time
- Requires knowledge of burst times (predefined in this implementation)
- Best case scenario benchmark for average total wait time `T_w`
**Characteristics:**
- Optimal average waiting time
- Risk of starvation for long processes
- Efficient for known workloads
- Difficult to implement in real systems (requires prediction)
**Queue Structure:**
```
Ready Queue (sorted by burst time):
[P3: 5ms] โ [P1: 10ms] โ [P4: 15ms] โ [P2: 20ms]
```
---
### 3. MLFQ - Multi-Level Feedback Queue
**Algorithm Type:** Preemptive
**Description:**
- Three-tier Ready Queue system with priority levels
- Single I/O Queue
- Dynamic priority adjustment based on behavior
- Prevents starvation while favoring interactive processes
**Queue Structure:**
```
Queue 1 (Highest Priority): Round Robin (Time Quantum T_q = 5)
Queue 2 (Medium Priority): Round Robin (Time Quantum T_q = 10)
Queue 3 (Lowest Priority): FCFS (No time quantum)
I/O Queue: FCFS (Unlimited devices)
```
**Priority Rules:**
- New processes and I/O returning processes โ Queue 1
- Process doesn't complete in Queue 1 โ Demoted to Queue 2
- Process doesn't complete in Queue 2 โ Demoted to Queue 3
- Higher queues preempt lower queues
- Queue N only runs when Queues 1 through N-1 are empty
**Advantages:**
- Balances turnaround time and response time
- Adapts to process behavior dynamically
- Prevents starvation through aging
- Favors I/O-bound (interactive) processes
---
## ๐ง Technical Implementation
### Process Definition
Each process consists of alternating CPU and I/O burst times:
```cpp
Process Structure: {CPU, I/O, CPU, I/O, ..., CPU}
```
**Requirements:**
- โ
Must begin with a CPU burst
- โ
Must end with a CPU burst
- โ
Alternates between CPU and I/O operations
**Example Process:**
```cpp
Process P1 = {5, 3, 8, 4, 6}; // CPU โ I/O โ CPU โ I/O โ CPU
```
### I/O Handling
**Unlimited I/O Devices Assumption:**
- All processes in I/O queue execute simultaneously
- All I/O burst counters decrement in parallel
- Processes leave I/O queue immediately upon completion
- Realistic for systems with high I/O parallelism
### Queue Operations
**Key Operations Implemented:**
- `Make_process()` - makes a queue of nodes by reading a process file
- `add_back()` - Add a node to the BACK
- `deQueue()` - delete a node from the FRONT
- `Print_proc_nodes()` - iterates the queue and prints the list of nodes
- `remove()` - removes a node from the middle of a queue
- `FCFS_SJF_increment_wait()` - increments the wait times of processes in the ready queue
- `FCFS_SJF_add_to_queue()` - ONLY for FCFS and SJF to transfer nodes between queues
- `FCFS_SJF_CPU_queue_timer()` - decrements CPU time of front node and increments global clock
- `FCFS_SJF_IO_queue_timer()` - decrements I/O time of all nodes simultaneously, increments total IO clock
- `MLFQ_increment_wait()` - increments all wait times of all ready queues for MLFQ
- `MLFQ_add_to_queue()` - ONLY for MLFQ to transfer nodes between queues
- `MLFQ_CPU_timer()` - Function only called for MLFQ Queue timers: Called by `Ready_1()`
- `MLFQ_IO_queue_timer()`- decrements I/O time of entire queue,increments total IO clock
- `Print_ready_IO()` - iterates the queue and prints the list of nodes.
- `Results()` - calculates and prints results: Ave T_wait, Ave T_turnaround, Ave T_response
---
## ๐ Repository Structure
```
process-scheduler/
โโโ Documentation/ # Project screenshots
โ โโโ Results_FCFS.png # FCFS algorithm output
โ โโโ Results_SJF.png # SJF algorithm output
โ โโโ Results_MLFQ.png # MLFQ algorithm output
โโโ Processes/ # Process definition files
โ โโโ p1.txt # Predefined Process 1
โ โโโ p2.txt # Predefined Process 2
โ โโโ ...
โ โโโ p8.txt # Predefined Process 8
โโโ processes.h # Process structure declarations
โโโ processes.cpp # Process management implementation
โโโ queues.cpp # Queue data structure implementation
โโโ sched_driver.cpp # Main driver and scheduling logic
โโโ README.md # This document
```
---
## ๐ Getting Started
### Prerequisites
**Development Environment:**
- Linux operating system (Ubuntu, Mint, Fedora, etc.)
- GNU g++ compiler (C++11 or higher)
- Code::Blocks IDE v20.03+ (optional)
- GDB debugger (for debugging)
- Make build system (optional)
### Compilation
**Method 1: Command Line (Recommended)**
```bash
# Clone the repository
git clone https://github.com/ADolbyB/process-scheduler.git
cd process-scheduler
# Compile with g++
g++ -std=c++11 -Wall -Werror *.cpp *.h -o sched_driver
# Run the scheduler
./sched_driver
```
**Method 2: With Debugging Support**
```bash
# Compile with debug symbols
g++ -g -std=c++11 -Wall -Werror *.cpp *.h -o sched_driver
# Launch with GDB
gdb ./sched_driver
# GDB commands:
# (gdb) run - Start execution
# (gdb) break main - Set breakpoint
# (gdb) next - Step over
# (gdb) step - Step into
# (gdb) print variable - Inspect variable
# (gdb) quit - Exit GDB
```
**Method 3: Code::Blocks IDE**
1. Launch Code::Blocks IDE
2. Create New Project:
- File โ New โ Project
- Console Application โ C++
- Name: `process-scheduler`
- Select project location
- Compiler: GNU GCC
3. Remove default `main.cpp`
4. Add project files:
- Right-click project โ Add files
- Select all `.cpp` and `.h` files
5. Build and Run: F9
### Usage
```bash
$ ./sched_driver
=>> Process Scheduler <<=
*** Make a Selection: ***
1) Run FCFS Algorithm
2) Run SJF Algorithm
3) Run MLFQ Algorithm
4) Exit
```
Select algorithm by number and observe:
- Process execution timeline
- Queue state changes
- CPU utilization
- Average waiting time
- Average turnaround time
---
## ๐ Output Examples
### FCFS Algorithm Output
[](Documentation/Results_FCFS.png)
**Performance Characteristics:**
- Execution order: P1 โ P2 โ P3 โ P4 (arrival order)
- No preemption or reordering
- Simple but potentially inefficient
---
### SJF Algorithm Output
[](Documentation/Results_SJF.png)
**Performance Characteristics:**
- Execution order: Sorted by CPU burst length
- Minimizes average waiting time
- Optimal for known workloads
---
### MLFQ Algorithm Output
[](Documentation/Results_MLFQ.png)
**Performance Characteristics:**
- Dynamic priority adjustment
- Time quantum enforcement
- Queue demotion on timeout
- Responsive to interactive processes
---
## ๐ก Key Concepts Demonstrated
### Operating Systems Theory
| Concept | Implementation |
|---------|----------------|
| **Process Scheduling** | Three distinct algorithms with different policies |
| **Context Switching** | Preemption in MLFQ with state preservation |
| **Queue Management** | Custom queue data structures for process lists |
| **CPU Burst** | Timed execution periods for computational work |
| **I/O Burst** | Simulated I/O operations with wait times |
| **Priority Scheduling** | Multi-level queues with dynamic priorities |
| **Starvation Prevention** | MLFQ aging and priority boost mechanisms |
### Data Structures
- **Linked List Queues** - Dynamic process queue management
- **Process Control Blocks (PCBs)** - Process state and metadata
- **Priority Queues** - SJF ordered insertion
- **Multi-Queue System** - MLFQ three-tier structure
### Performance Metrics
**Calculated for each algorithm:**
- Average Waiting Time
- Average Turnaround Time
- CPU Utilization
- Context Switch Count
---
## ๐งช Testing & Validation
**Test Cases:**
- โ
Single process execution
- โ
Multiple processes with varying burst times
- โ
I/O-bound vs CPU-bound process mixes
- โ
Process arrival order variations
- โ
Queue preemption scenarios (MLFQ)
- โ
Edge cases (empty queues, single burst processes)
**Validation Methods:**
- Manual calculation verification
- Output log analysis
- Performance metric comparison
- GDB step-through debugging
---
## ๐ Learning Outcomes
**Skills Demonstrated:**
- โ
Operating system scheduling algorithm implementation
- โ
Custom data structure design (queues, process lists)
- โ
C++ object-oriented programming
- โ
Pointer management and memory efficiency
- โ
Algorithm complexity analysis
- โ
Linux development environment proficiency
- โ
Professional code documentation
---
## ๐ Academic Context
**Course Learning Objectives Met:**
1. Understand CPU scheduling algorithms and policies
2. Implement process management data structures
3. Analyze algorithm performance trade-offs
4. Design efficient queue management systems
5. Debug complex C++ systems code
**Project Requirements:**
- Multiple scheduling algorithms
- Predefined process workloads
- Queue-based process management
- Performance metrics calculation
- Clean, documented code
---
## ๐ค Contributing
This is a completed academic project, but improvements are welcome:
- ๐ Documentation enhancements
- ๐ Bug fixes
- ๐ก Additional scheduling algorithms (Priority, Round Robin variants)
- ๐ Enhanced visualization
- โก Performance optimizations
---
## ๐ License
This project is licensed under the GNU GPL v3 License - see the [LICENSE.md](https://github.com/ADolbyB/process-scheduler/blob/main/LICENSE.md) file for details.
**Academic Integrity Notice:** This repository represents completed coursework (98/100). Use as a learning resource to understand scheduling algorithms and C++ implementation, but develop your own solutions for assignments.
---
## ๐ง Contact
**Developer:** [Joel Brigida](https://github.com/ADolbyB)
**LinkedIn:** [Joel Brigida](https://www.linkedin.com/in/joelmbrigida/)
**Course:** Operating Systems, Fall 2021
Questions about implementation details? Feel free to open an issue!
---
## ๐ Repository Stats




---
**Master Operating Systems. Understand Scheduling. Build Real Systems.**
*From theory to implementation - CPU scheduling algorithms in C++* โ๏ธ
[](https://github.com/ADolbyB)