Skip to content

IsaacShaheem/Round-Robin-Algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CIS*3110 A1 Round Robin

Full Name: Isaac Shaheem

Student ID: 1345958

Overview

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:

  1. Average turnaround time
  2. Average waiting time
  3. Average response time

Installation

Linux

This project is intended to be built and run on Linux.

To compile the program, run:

make

This will produce an executable named rr.

To remove the executable and object files, run:

make clean

macOS

Prerequisites: Xcode Command Line Tools (provides gcc and make)

Install prerequisites:

xcode-select --install

To compile the program, run:

make

This will produce an executable named rr.

To remove the executable and object files, run:

make clean

Windows

This project is intended for Unix-like environments. On Windows, it is recommended to use WSL2.

  1. Install WSL2 and an Ubuntu distribution.
  2. Open the Ubuntu terminal and install build tools:
sudo apt update
sudo apt install build-essential

To compile the program, run:

make

This will produce an executable named rr.

To remove the executable and object files, run:

make clean

Usage

Run 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.

Input File Format

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 Runs

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.83

The output consists of three space-separated values:

  1. Average turnaround time
  2. Average waiting time
  3. Average response time

Each value is printed with exactly two decimal places.

Round-Robin-Algorithm

A c program that simulates a round robin scheduling algorithm that operating systems use.

About

A c program that simulates a round robin scheduling algorithm that operating systems use.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors