A comprehensive CPU scheduling simulator written in C. This command-line tool implements various process scheduling algorithms used in operating systems, providing detailed metrics (Turnaround Time, Waiting Time, Response Time) and a text-based Gantt chart visualization for each simulation.
This project simulates the execution of processes based on different scheduling policies. It allows users to input process details (Arrival Time, Burst Time, Priority) and observe how different algorithms handle the workload. It is designed for educational purposes to understand the core concepts of OS process management.
The simulator supports the following algorithms:
- FCFS (First Come First Serve)
- Round Robin (RR) - User-defined time quantum.
- Priority Scheduling (Non-Preemptive) - Processes with lower priority integer values have higher priority.
- SJF (Shortest Job First) - Non-Preemptive.
- SRTF (Shortest Remaining Time First) - Preemptive version of SJF.
- Multilevel Queue (MLQ) - Fixed priority scheduling where System processes use RR and User processes use FCFS.
- Multilevel Feedback Queue (MLFQ) - Dynamic priority scheduling with 3 queues (Q0=RR4, Q1=RR8, Q2=FCFS).
The core logic is built around the Process structure:
typedef struct {
int pid;
int arrival_time;
int burst_time;
int priority;
int remaining_time;
int waiting_time;
int turnaround_time;
int completion_time;
int current_queue;
} Process;Key components:
- Process Management: Functions to reset process states between simulations.
- Visualization: A
print_tablefunction that outputs a formatted table of metrics and a textual Gantt chart. - Sorting Utilities: Helper functions to sort processes by arrival time or priority.
- GCC Compiler (or any standard C compiler like Clang or MSVC).
- Terminal or Command Prompt.
To compile the project, navigate to the project directory and run:
gcc main.c -o scheduler- Run the executable:
- Linux/macOS:
./scheduler - Windows:
scheduler.exe
- Input the number of processes.
- For each process, enter the following integers separated by space:
Arrival TimeBurst TimePriority(Lower number = Higher priority)
- Select an algorithm from the menu to simulate.
Below is an example of a simulation running First Come First Serve (FCFS):
Enter number of processes: 3
Process 1 [Arrival, Burst, Priority]: 0 5 2
Process 2 [Arrival, Burst, Priority]: 1 3 1
Process 3 [Arrival, Burst, Priority]: 2 1 3
SCHEDULER SIMULATOR
1. FCFS
2. Round Robin
3. Priority (Non-Preemptive)
4. SJF (Shortest Job First - Non-Preemptive)
5. SRTF (Shortest Remaining Time First - Preemptive)
6. Multilevel Queue (System=RR, User=FCFS)
7. Multilevel Feedback Queue (Q0-Q2)
8. Exit
Choice: 1
--- Simulating FCFS ---
Gantt Chart: | P1 (0-5) | P2 (5-8) | P3 (8-9) |
----------------------------------------------------------------------------------
| PID | Priority | Arrival | Burst | Completion | Turnaround | Waiting |
----------------------------------------------------------------------------------
| 1 | 2 | 0 | 5 | 5 | 5 | 0 |
| 2 | 1 | 1 | 3 | 8 | 7 | 4 |
| 3 | 3 | 2 | 1 | 9 | 7 | 6 |
----------------------------------------------------------------------------------
Average Waiting Time: 3.33
Average Turnaround Time: 6.33
CPU Utilization: 100.00%
----------------------------------------------------------------------------------
This project is licensed under the MIT License - see the LICENSE file for details.