This project implements a Round Robin (RR) CPU scheduling simulator written in C. The program reads an input file containing a list of processes and simulates how a CPU would schedule them using the Round Robin algorithm. The user can specify a time quantum and an optional context switch cost via command-line arguments.
Each process is defined by an arrival time and a burst time. The scheduler maintains a FIFO ready queue, executes each process for at most one quantum at a time, and re-enqueues processes that do not complete within their allocated quantum. The remaining burst time is updated after each execution.
An optional context switch cost is included to simulate real operating system behavior. This cost represents the overhead of switching from one process to another and is added to the simulated CPU clock only when an actual switch between two different processes occurs. No context switch cost is incurred when the first process starts at time t=0, when the CPU was previously idle, when a process finishes and no new process starts immediately after, or when there is only a single process in the ready queue and it continues running.
At the end of the simulation, the program outputs the following average metrics across all processes:
- Average turnaround time
- Average waiting time
- Average response time
This project is intended to be built and run on Linux.
To compile the program, run:
makeThis will produce an executable named rr.
To remove the executable and object files, run:
make cleanPrerequisites: Xcode Command Line Tools (provides gcc and make)
Install prerequisites:
xcode-select --installTo compile the program, run:
makeThis will produce an executable named rr.
To remove the executable and object files, run:
make cleanThis project is intended for Unix-like environments. On Windows, it is recommended to use WSL2.
- Install WSL2 and an Ubuntu distribution.
- Open the Ubuntu terminal and install build tools:
sudo apt update
sudo apt install build-essentialTo compile the program, run:
makeThis will produce an executable named rr.
To remove the executable and object files, run:
make cleanRun the program using the following format:
./rr <input_file> [quantum] [context_switch]Parameters:
- input_file (required): Path to a text file containing the process list
- quantum (optional): Time quantum (default = 10). Must be greater than 0
- context_switch (optional): Context switch cost (default = 0). Must be non-negative
If invalid parameters are provided (e.g., quantum ≤ 0 or context switch < 0), the program prints "Invalid parameters" and exits. If the input file contains no processes, the program exits.
Each line of the input file represents a single process in the format: arrival_time,burst_time
Assumptions:
- Arrival times are non-negative integers
- Burst times are positive integers
- Processes are sorted by arrival time
- Input files are properly formatted
Example input file (example.txt):
0,5
0,3
0,6
1,8
9,2
10,16./rr example.txt
15.50 8.83 8.83./rr example.txt 2
19.67 13.00 4.00./rr example.txt 2 1
30.33 23.67 6.83The output consists of three space-separated values:
- Average turnaround time
- Average waiting time
- Average response time
Each value is printed with exactly two decimal places.
A c program that simulates a round robin scheduling algorithm that operating systems use.