Giter VIP home page Giter VIP logo

cpu-scheduling's Introduction

CPU Scheduling Algorithm Simulator

A programming exercise that simulates the basic CPU scheduling algorithms:

  • First-Come-First-Serve (FCFS)
  • Shortest-Job First (SJF)
  • Shortest-Remaining-Time-First (SRTF)
  • Round-Robin (RR)

Instructions

Input

The program reads the following from standard input: The first line contains three integers separated by space, $X\hspace{.1cm}Y\hspace{.1cm}Z$.

  • $X$ denotes the CPU scheduling algorithm.
  • $Y$ denotes the number of processes where $3 \leq Y \leq 100$
  • $Z$ denotes a time slice value (applicable for Round-Robin algorithm only), where $1 \leq Z \leq 100$. If the CPU scheduling algorithm indicated by the value of $X$ is not the Round-Robin algorithm, this value must be set to 1 but ignored.

See the table below for the CPU scheduling algorithm and the corresponding value of $X$.

CPU Scheduling Algorithm Value of $X$
FCFS 0
SJF 1
SRTF 2
RR 3

There will be $Y$ lines of space-separated integers $A\hspace{.1cm}B\hspace{.1cm}C$ where $A$ is the process ID, $B$ is the arrival time, and $C$ is the burst time.

Output

The output includes the following:

  • $Y$ lines of processes with the start time, end time, and total waiting time. If there are multiple start and end times for each process, display them in order. (where $S_1 ... S_N, \hspace{.1cm} E_1 ... E_N, \hspace{.1cm} \text{WT} \geq 0 $)

  • An additional last line, where ๐ด๐‘Š๐‘‡ indicates the average waiting time of the processes. The output should be sorted according to the process ID $A$.

Average waiting time: <AWT>

Usage

To run the simulator with manual input, run:

python main.py

To run the simulator with an input file, run:

# On Windows
type ./path/to/input.txt | python main.py
# On Mac/Linux
cat ./path/to/input.txt | python main.py

To run the simulator with an input and output file, run:

# On Windows
type ./path/to/input.txt | python main.py > ./path/to/output.txt
# On Mac/Linux
cat ./path/to/input.txt | python main.py > ./path/to/output.txt

Test

To run the test cases for all algorithms, run:

python test.py

To run all the test cases for a certain algorithm, run:

python test.py --algo algorithm_name

To run a certain test case for a certain algorithm, run:

python test.py --algo algorithm_name --case n
# To use ./test/RR/input02.txt as a test case, run:
python test.py --algo rr --case 02

To run a single test case, run:

python test.py --input input.txt --output expected_output.txt

or using the shorthand:

python test.py -i input.txt -o expected_output.txt

cpu-scheduling's People

Contributors

nicapos avatar justjelooo avatar cheafernandez avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.