Sie sind auf Seite 1von 17

Bharat Krishna Raghavan ITM 513 Spring 2010

CWID: A20245965 Main Campus


1

FINAL PROJECT
Project Description
This project deals with the simulation of CPU scheduling algorithms with Python. The
following algorithms are simulated:
First Come First Serve (FCFS)
Shortest Job First
Priority Scheduling
Round Robin
The metrics such as finishing time, waiting time, total time taken for the processes to
complete, number of rounds, etc are calculated and Gantt charts are plotted.
Software Architecture
There are four files for the four scheduling algorithms. They are made into a package
called files. This package is imported by the file which has the menu. Each of the four
files in the package files import the numpy & matplotlib python libraries.







<<import>>


CPUSh.py




<<import>>
<<import>>
fcfs
priority
rr
sjf
files

numpy

matplotlib
Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
2

Use Case Diagram


The user runs the CPUSh.py file which loads the 4 files.

Description of the Scheduling Algorithms
First-Come, First-Served Scheduling: In this scheme, the process that requests the
CPU first is allocated the CPU first.
Priority Scheduling: A priority is associated with each process, and the CPU is allocated
to the process with the highest priority.
Shortest Job First Scheduling: This algorithm associates with each process the length of
the process's next CPU burst. When the CPU is available, it is assigned to the process
that has the smallest next CPU burst.
Round-Robin Scheduling: The round-robin (RR) scheduling algorithm is designed
especially for timesharing systems. It is similar to FCFS scheduling, but preemption is
added to switch between processes. A small unit of time, called a time quantum or time
slice, is defined. The CPU scheduler goes around the ready queue, allocating the CPU
to each process for a time interval of up to 1 time quantum.
[1]
Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
3

Installation
The system running this program should have python installed.
In addition to that, 2 python libraries- numpy (http://numpy.scipy.org/) and matplotlib
(http://matplotlib.sourceforge.net/) should be installed.

Runtime Requirements
The program can be run by executing the CPUSh.py file.

Insights
This project helped me reinforce the concepts learnt throughout the course. It gave me
a better understanding of pythons semantics. I also explored some python libraries like
numpy and matplotlib. Python can be extended by numerous libraries like this. This
shows the wonder of open source.

Expected Results
The program should be able to simulate the CPU scheduling algorithms for any value of
the input and calculate the various metrics and plot the Gantt chart.

Development &Test Environment
Version of Python: Python 2.6
IDE Used: Wing IDE 101, Version 3.2.4
Operating System: Windows Vista 64 bit SP1
Processor: Intel Core 2 Duo P7550 2.27 GHz
RAM: 4 GB





Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
4

Screen Captures



The menu screen which allows the user to select which algorithm he wants to run








Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
5






According to the option selected the module is loaded







Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
6






The data is entered and return key is pressed. All the metrics are calculated for the entered
data.







Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
7






A Gantt chart is drawn for the processes showing the time taken for each process to complete





Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
8






If the number of bust times does not match with the number of arrival times, an error message is
printed.







Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
9






Metrics for the Shortest Job First Algorithm







Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
10






Gantt chart for the Shortest Job First Algorithm





Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
11





Metrics for the Priority Scheduling Algorithm








Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
12






Gantt chart for the Priority Scheduling Algorithm





Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
13





Metrics for Round Robin Scheduling Algorithm with time quantum=20






Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
14






Gantt chart for the Round Robin Scheduling Algorithm with time quantum = 20





Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
15





Metrics for Round Robin Scheduling Algorithm with time quantum = 10

Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
16






Gantt chart for the Round Robin Scheduling Algorithm with time quantum = 10





Bharat Krishna Raghavan ITM 513 Spring 2010
CWID: A20245965 Main Campus
17

Project Summary
The four CPU scheduling algorithms namely First Come First Served (FCFS), Shortest
Job First (SJF), Priority scheduling and Round Robin (RR) scheduling are simulated
using Python. The various metrics are calculated and Gantt charts are plotted. Numpy
which is python library was used for doing mathematical calculations. The matplotlib
library was used to plot the Gantt charts. The code for this project is modular. The code
for the four algorithms are put into a package and imported by the file which acts as the
menu.
Thus the above mentioned features were implemented, resulting in successful
completion of the project.

References
[1] Silberschatz, Galvin, Gagne: Operating System Concepts, 7th Edition

Das könnte Ihnen auch gefallen