Write a simulation to analyze CPU scheduling algorithms. You will simulate the following schedulers:
First Come First Serve
Preemptive Shortest Job First
Priority (preemptive)
Round Robin with quantum=20.
All time units should be an integral number of milliseconds. These milliseconds don't have to literally take a millisecond while running. Don't make things happen in "real time".
Simulate context switches between processes, each of which will require 5 ms. Context switches should not be preempted.
You may write your program in a language of your choice, but I must be able to run it somewhere.
Your program will need to specify an input file name from the command line and a single flag. The flag is optional on the command line. If it is specified, your program will produce verbose output (see below), otherwise it will produce the default output only.
Suppose you write a program called CPUSim. The command line format would be:
CPUSim infile -vor
java CPUSim infile -vwhere infile is the name of the input file and the optional -v specifies verbose output.
You can specify command line arguments in eclipse by modifying the Run Configurations for your project so you aren't stuck only running from the command line.
Your program will read processes from a file. The first line of the file will contain n:the number of processes to simulate which will have a value between 1 and 1000.
There will then be n lines (one for each process) containing 4 integers separated by a single space:
5 1 1 5 65 2 1 10 73 3 1 15 17 4 7 20 128 35 5 25 2
The line should be just numbers separated by a space with no labels.
The file testOut.txt contains verbose output for the example input above. Your calculations may differ a bit from mine depending on your design and scheduling decisions. They do not need to match exactly.
There is an additional sample input file, procTest.txt and its verbose output procTest_output.txt. You can make other input files using ProcGen.java Java program provided.
Your code should be readable and understandable. To facilitate this you should include two varieties of comments. The standard mechanical comments will indicate what code is doing, what parameters/return values mean etc.
You will also include thematic comments. These will describe in general terms the activities and events surrounding the "process" structure in your simulation. Document what is done to the processes, how they are manipulated, how they change. If your code tells a story, the process is the protagonist.
Thematic comments should begin with a "--". So in Java and C++ you would use //-- or /*-- to indicate the beginning of a thematic comment.
Start early.
Make each iteration of an outer loop represent 1 msec. Each iteration should update each process's statistics and make any state changes necessary.
This is not an exercise in syntax and semantics, it is all about the simulation. If you find yourself getting caught up in details, stop and ask for help.
Don't run with scissors.
Create a ProcessInfo class to contain the all of the information associated with a process.
Create a Scheduler class that contains all of the information and data that is common to each scheduler. The Scheduler class could implement a simple algorithm like FCFS, or it could be abstract.
Create subclasses of the Scheduler class for each other scheduling algorithm.
Make the simulation only require the methods in the Scheduler object. Use polymorphism with the subclasses to get different behaviors.