Skip to content

A CPU scheduling simulator written in C implementing FCFS, Round Robin, Priority, SJF, SRTF, MLQ, and MLFQ algorithms.

License

Notifications You must be signed in to change notification settings

Oreo80/scheduler-sim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CPU Scheduling Simulator

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.

Overview

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.

Supported Algorithms

The simulator supports the following algorithms:

  1. FCFS (First Come First Serve)
  2. Round Robin (RR) - User-defined time quantum.
  3. Priority Scheduling (Non-Preemptive) - Processes with lower priority integer values have higher priority.
  4. SJF (Shortest Job First) - Non-Preemptive.
  5. SRTF (Shortest Remaining Time First) - Preemptive version of SJF.
  6. Multilevel Queue (MLQ) - Fixed priority scheduling where System processes use RR and User processes use FCFS.
  7. Multilevel Feedback Queue (MLFQ) - Dynamic priority scheduling with 3 queues (Q0=RR4, Q1=RR8, Q2=FCFS).

Structure

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_table function that outputs a formatted table of metrics and a textual Gantt chart.
  • Sorting Utilities: Helper functions to sort processes by arrival time or priority.

Getting Started

Prerequisites

  • GCC Compiler (or any standard C compiler like Clang or MSVC).
  • Terminal or Command Prompt.

Compilation

To compile the project, navigate to the project directory and run:

gcc main.c -o scheduler

Usage

  1. Run the executable:
  • Linux/macOS: ./scheduler
  • Windows: scheduler.exe
  1. Input the number of processes.
  2. For each process, enter the following integers separated by space:
  • Arrival Time
  • Burst Time
  • Priority (Lower number = Higher priority)
  1. Select an algorithm from the menu to simulate.

Example Output

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%
----------------------------------------------------------------------------------

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A CPU scheduling simulator written in C implementing FCFS, Round Robin, Priority, SJF, SRTF, MLQ, and MLFQ algorithms.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages