This is a CPU scheduling simulator project for the Operating Systems 330 course at NYIT by Federico Martinez Fernandez.
CPU Scheduling is the process of choosing what and when each process runs on a CPU. There are different algorithm to do CPU scheduling with different purposes.
Round Robin is a basic scheduling algorithm. It works by going around each process and giving each the maximum amount of time that it is allowed until either the process finishes processing or the time allowed runs out, whichever happens first. It then goes to the next process until it reaches the end and then goes back to the start of the queue.
- Make sure Go is installed. You can find official install instructions here
- Go to the src folder:
cd src - Run the command
make build - Go to the root directory:
cd .. - Execute the binary in the bin folder using the command:
bin/cpu_scheduling_proj input.csv Time_Quantum
You can find screenshots that show the output for the time quantums 1 through 5 in the screenshots directory.
cpu_scheduling_proj/
│
├── src/
│ ├── clock.go
│ ├── cpu.go
│ ├── go.mod
│ ├── importFile.go
│ ├── Mmkefile
│ └── main.go
│ └── process.go
│ └── scheduler.go
│
├── bin/
│ └── cpu_scheduling_proj
│
├── screenshots/
│ ├── quantum_1.png
│ ├── quantum_2.png
│ ├── quantum_3.png
│ ├── quantum_4.png
│ └── quantum_5.png
│
└── README.md
└── input.csv
│
File: src/process.go
Description:
The Process class represents a process in the simulation. It has all of the necessary attributes required for scheduling and getting statistics.
Attributes:
pid int: The Process ID.arriveTime float64: The time at which the process arrives.burstTime float64: Total CPU time required by the process.timeRunning float64: The amount of time that the process has run for.firstTimeExeuted float64: The time at which the process was executed for the first time.completionTime float64: The time at which the process finished execution.turnAroundTime float64: The total amount of time from arrival to completion.waitingTime float64: Total time the process spends waiting in the ready queue.responseTime float64: Time from arrival until the first time the process gets the CPU.
Methods:
func (p Process) getStatus() stringReturns a string with all of the processes information
func (p *Process) increaseTimeRunning(timeToAdd float64)Increases the time the process has been running by the specified parameter
func (p *Process) setCompleted(currenTime float64)Sets the process as completed and calcultes statistics, which are saved to the attributes
File: src/cpu.go
Description:
The CPU class represents a CPU in the simulation. It has all of the necessary attributes required for running a process and getting the CPUs utilization.
Attributes:
clock Clock: The CPU's clock.timeQuantum float64: The time quantum specified.
Methods:
func (c *CPU) run(p *Process) boolRuns the process specified as a parameter and returns a boolean theat indicates if the process finished running or had to be preempted
func (c *CPU) getUtilization(processCount int)Prints the CPU's utillization. It uses the processCount parameter to calculate the throughput.
File: src/clock.go
Description:
The Clock class represents a clock in the simulation. It has all of the necessary attributes required to keep track of the time.
Attributes:
currentTime float64: The current time.totalExecutionTime float64: Total time that the CPU has been executing a process for.totalIdleTime float64: Total time that the CPU has been ideling for.contextSwitchCount int: The number of context switches done.
Methods:
func (c *Clock) tick(time float64)Ticks the clock by the specified amount of time.
func (c *Clock) addExecutionTime(time float64)Increases the execution time by the specified amount of time.
func (c *Clock) addIdleTime(time float64)Increases the idle time by the specified amount of time.
File: src/importFile.go
Description:
The ImportFile class implments all of the necessary functions required to read the input csv file that contains the processes.
Attributes: It has no attributes
Methods:
func importProcesses(filepath string) []ProcessReads the csv file at the filepath specified and returns the processes as a slice (similar to an array in other programming languages) with each process as an object of time Process.
File: src/scheduler.go
Description:
The Scheduler class implments all of the necessary functions required to schedule the processes using the Round Robin algorithm.
Attributes:
processes []Process: The slice that contains all of the processes to run.
Methods:
func (s *Scheduler) start(c *CPU, completedProcesses *[]Process)Starts the scheduler with the specified CPU and with the slice where the completed processes will be moved to so that they can be used to get statistics.
func (s *Scheduler) getProcessesForTime(currentTime float64) []intReturns a slice with the indexes of the processes that have arrived at the time specified.
File: src/main.go
Description:
The Main file serves as the starting point of the application. It handles user input, initiates the scheduling simulation, and displays the results.
Methods:
func main()The main function that gets called when the program is started.
func getStatsFromCompletedProcesses(processes []Process)It prints statistics for the processes executed.
Usage Example:
bin/cpu_scheduling_proj input.csv 2This project shows how round robin can be used to schedule processes in a CPU. The higher the time quantum is, the less time all of the processes take to run and wait.
This project is licensed under the MIT License. You can read it in the LICENSE.txt file.