Skip to content

nneha19/CPUSchedPlusPlus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPUSched++ - CPU Scheduling Simulator (C++)

A console-based C++ project that simulates key CPU scheduling algorithms:

  • FCFS (First-Come, First-Served)
  • SJF (Shortest Job First)
  • Round Robin (with Time Quantum 4)
  • Priority Scheduling

Built from scratch using core C++ concepts like vectors, sorting, conditionals, and process struct modeling, this tool visualizes execution order, timing metrics, and Gantt charts — mimicking how a real CPU scheduler functions. image


🛠️ Features

  • Interactive input for process details
  • 📊 Gantt chart-like visual display
  • 🧮 Calculates: Completion Time, Turnaround Time, Waiting Time
  • 🔁 Round Robin with fixed time quantum (4 units)
  • 📋 Priority support (lower number = higher priority)

🚀 Algorithms Implemented

1. First-Come, First-Served (FCFS)

Logic: Sort processes by arrival time and execute one after another.

sort(processes.begin(), processes.end(), compareByArrivalTime);

Example:

PID Arrival Burst
1 0 4
2 1 3

🕐 Gantt Chart: | P1 (0–4) | P2 (4–7) |


2. Shortest Job First (Non-Preemptive)

Logic: At each time, pick the process with the smallest burst that has arrived.

if (p.arrivalTime <= currentTime && p.burstTime < minBurst)

3. Round Robin (Time Quantum = 4)

Logic: Use a queue; each process gets 4 units in turn until done.

queue<Process> q;
remainingBurst[p.pid] = p.burstTime;

4. Priority Scheduling

Logic: Execute by priority, resolve ties using arrival time.

sort(processes.begin(), processes.end(), [](a, b) {
    return a.priority < b.priority || (a.priority == b.priority && a.arrivalTime < b.arrivalTime);
});

📸 Sample Output

Now executing Process P2 at time 0
Processing...
Process P2 finished at time 3
-----------------------------------------

🕐 Final Table:

PID Arrival Burst Arrival Burst Burst
1 0 4 4 4 0

🔧 How to Run

g++ main.cpp -o CPUSchedPlusPlus
./CPUSchedPlusPlus

Or compile all .cpp files together, depending on your setup.


📁 File Structure

├── main.cpp
├── scheduler.cpp
├── utils.cpp
├── headers/
│   ├── process.h
│   ├── fcfs.h
│   ├── sjf.h
│   ├── rr.h
│   ├── priority.h
│   ├── scheduler.h
│   └── utils.h
├── algorithms/
│   ├── fcfs.cpp
│   ├── sjf.cpp
│   ├── rr.cpp
│   └── priority.cpp
└── README.md

🧠 Why This Project?

As part of core Computer Science learning, this project strengthens understanding of:

  • OS scheduling theory
  • Time management of processes
  • Simulation of real CPU-like behaviour
  • C++ data structures and logic building

🏁 Future Improvements

  • Add Preemptive SJF or Multilevel Queues
  • Export table as CSV
  • GUI-based interface (maybe in Qt or web)

👩‍💻 Author

Neha Ghariyal
📫 GitHub | 📧 nehaghariyal19@gmail.com

About

A terminal-based CPU Scheduling Simulator written in C++.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors