A Java Based Visual Tool to Learn CPU Scheduling
Algorithms
Neetu Jain1 and P. V. Suresh2
1
Research Scholar, SOCIS, IGNOU, New Delhi
2
Associate Professor, SOCIS, IGNOU, New Delhi
E-mail: 1 neetugupta78@[Link]
Abstract—CPU scheduling algorithms are integral part of E-learning through visualization animated tools, animated
learning operating system. Over the years, it has been expe- tools using various multimedia techniques is effective in CS
rienced that initially CS students face a lot of problems in education [3][4]. A visual tool or diagram has always been
understanding and further implementing the various scheduling
algorithms. Also generating and regenerating Gantt Charts is effective and helpful in better learning and understanding.
faced with difficulties by many CS students. A visual tool or It has also been experimented in past that students using
diagram has always been effective way in better learning and such tools had had better understanding on the concepts
understanding. We developed a Java and Java Swing based and consequently preformed better [4]. Simplicity and easy
application, to visually explain various scheduling algorithms. understanding of such tools is an important criterion to develop
User can enter the runtime details of processes and the tool is
capable of graphically showing the execution of processes inside such education oriented tools. Many tools have been developed
the system using a particular scheduling algorithm. The tool is in past to simulate operating system scheduling algorithms. In
also capable of doing calculations different effectiveness criteria [5] authors present such a tool developed for use by operating
of an algorithm like waiting time of each process, average waiting system learners to gain insight on the Linux scheduling
time and turnaround time. Proposed tool has used different colors algorithm.
to depict processes to have much better understanding of the
operations inside the system. We developed a Java and Java Swing based application,
Index Terms—Scheduling Algorithm Visualization, CPU to visually explain various scheduling algorithms. User can
Scheduling Algorithm, Visual Tool, Computer Science (CS) enter the process details using simplistic provided graphical
Education. user interface. It also shows calculations of waiting time of
each process, average waiting time and turnaround time. We
I. I NTRODUCTION used multicolored effects to generate more effective Gantt
Operating System is a required course that is taught to the charts. In this paper we present the feature details of the tool
CS graduate and post graduate students. For a CS student it developed and its usefulness. In sections II, III we present
is very important to understand the topics of the subject in the theory of popular CPU scheduling algorithms, which are
depth. Broadly, it includes learning of architecture and various implemented in the proposed tool. In section IV the details
functioning of an operating system. According to [1] the of proposed tool are presented. The details are spread into
important critical functions of an operating system are broadly different subsections, each highlighting the various features
categorized as Process Management, Memory Management, available with the application. In section V, we present the
File Management, Security and Protection. tests run on the tool those are verified manually to check the
In this paper we focus on the important aspect of Process accuracy of the application. Finally in Section VI we conclude
Management. In multiprogramming systems, many processes the paper mentioning the future work planned in this work.
are executed simultaneously. All active processes demand CPU
time for execution. It is the responsibility of operating system II. T HEORY
to apply a strategy to meet the demand of CPU by various
processes. While meeting the requirement of processes, the CPU scheduling algorithms are used by operating system to
critical task of operating system is to achieve maximum CPU effectively maximize the CPU utilization in multiprogramming
utilization. This is a fundamental function of any operating systems. We have focused on simulating broadly used four
system and is called as CPU scheduling [1]. scheduling algorithms i.e. First Come First Serve (FCFS),
Various CPU scheduling algorithms has been designed Shortest Job First (SJF), Round Robin and Priority Scheduling.
considering different architectures of operating systems. There Operating system maintains a queue all the processes those
are few popular scheduling schemes that are being taught to are ready to run and waiting for CPU called as ready queue.
students as a part of process management. Learning these algo- Any process that requires CPU time must enter the ready
rithms is usually find challenging to CS students. It is equally queue. Operating system chooses a process from ready queue
difficult for teachers to make students understand these in a to allocate CPU, depending on the scheduling scheme imple-
simplified way manually. Using textbook description and paper mented. Burst time is the CPU time required by the process
approach it is difficult to grasp the required understanding. for its execution.
We briefly discuss the four popular scheduling algorithms B. Average waiting time
taught as part of the course as below [1] [2]. It is an average of waiting time of all the processes in the
system. This is used as a criterion to compare the effectiveness
A. First Come First Serve (FCFS) of scheduling algorithms. For example if there are three
FCFS is the simplest CPU scheduling algorithm. In this processes P1, P2, P3 in the system and waiting time of each
scheduling scheme the process that requests the CPU first is is 5, 10, 15 respectively, then:
allocated first. Process to be executed enters the ready queue. Average waiting time = Sum ofTotal
waiting time of all the processes
number of processes
In this scheduling scheme the ready queue is implemented as C. Turnaround time
First in First out (FIFO). Process is added at the tail of the
ready queue. When the CPU is free, the process at the head This is the criteria from the process point of view. It is
of ready queue is given the chance to execute. value of how much time it will take to execute the process. It
is the time when the process is entered in the system till the
B. Shortest Job First (SJF) completion of the process. Mathematically:
Turnaround time = Time spent in memory + ready queue +
In Shortest Job first algorithm the burst time required by CPU time + I/O time
the process to complete is used as a parameter to do the Turnaround time = Interval from the time of process sub-
scheduling. The process with smallest burst time is given the mission to the time of completion
preference and allocated the CPU. If the two processes have
the same burst time simply FCFS scheme is applied to break D. Average turnaround time
the tie. It is an average of turnaround time of all the processes in
the system. It is simply calculated as:
C. Round Robin Average Turnaround time = Sum of turnaround time of all the processes
Total number of processes
Round Robin scheduling is primarily for time sharing IV. D ESIGN OF THE T OOL
systems. Operating system defines a time slice usually called
In this paper we propose a java based visual tool for
as time quantum. In this scheduling scheme the ready queue
interactive learning the discussed CPU scheduling algorithm
behaves as a circular queue. CPU is allocated to each process
used by an operating system.
in the ready queue for time quantum period in a circular
Visually the tool is divided into four areas. In the left pane
fashion. When the time quantum is finished, CPU is preempted
we can enter the process details like process name, process
from the process and allocated to the next process waiting in
burst time, priority etc. In the right pane all the implemented
the ready queue. If the process is not finished in the allocated
CPU scheduling algorithms are listed as choices. Centre Pane
time quantum, it is put at the tail of the ready queue again
is the area dedicated to showing the execution of processes
waiting for the next time slice of CPU.
in the form of Gantt chart. The bottom pane shows the
calculations and results of the effectiveness of the algorithm
D. Priority
applied. The tool is shown in figure 1.
Priority scheduling is implemented on a parameter associ- User can see the process details in the leftmost pane area as
ated with each process called as priority. For this scheduling in figure 2. Left Pane area is further divided into two portions.
scheme each process is attached some priority with it. At any In the upper portion is showing the list of process in a tabular
moment a process in the ready queue with highest priority is form. For each process, process name, burst time and priority
allocated the CPU. Assigning the priority is a task to be done of process is shown as entered by user.
either internally by operating system or externally. In the lower area the buttons are provided as shown in figure
2. Process Details button is to enter the processes and their
III. C ALCULATIONS details. On clicking this button Add Process dialog box is
popped up as shown in figure 3.
All the scheduling schemes discussed in the section II have
The Add Process dialog box has fields to provide Process
their own pros and cons. The effectiveness of scheduling
Name and Burst time. Add button is used to enter the multiple
algorithms is compared on the basis of few criteria[1]. These
processes. When all the processes are entered user should enter
criteria are briefly discussed further in this section. We have
the Done button. In case of Priority scheduling algorithms is
used the following discussed mathematical formulae to cal-
selected, the Add Process dialog box also has a field to enter
culate and show the values of these criteria in the developed
the priority associated with the process as in figure 4.
tool.
Start Execution button is to execute the processes using the
CPU scheduling algorithm as selected in right pane. Clear
A. Waiting time
Process Details button is used to delete all the previously
A process spends time in ready queue waiting for its turn entered processes. This will clear all the previous data entered.
for the CPU. Waiting time of a process is the sum of periods Again you can choose Process Details button to enter new
spent waiting in the ready queue of the operating system. process information.
Fig. 1. CPU Scheduling Algorithm Tool
A. Left Pane- Process Details Area
B. Right Pane – List of CPU Scheduling Algorithm
In the right side of all the implemented four scheduling
algorithms are listed one of which to be applied can be
selected. In the figure 1 First Come First Serve scheduling
scheme is selected is shown.
C. Center Pane – Process Execution and Gantt Chart
The execution of processes and generation of Gantt chart is
shown in the centre area. On clicking of the Start Execution
button on the left, the processes start executing. The selected
scheduling algorithm is applied. Gantt chart depiction is shown
pictorially to simulate the effect of process execution in the
centre area. Different colors are associated with each process
for better visualization and understating.
D. Bottom Pane – Algorithm Performance calculation
In the bottom of centre pane different performance criteria
of the applied scheduling algorithm are calculated and results
are shown. At present we are calculating four criteria. They
are waiting time of each process, Average waiting time of the
scheduling algorithm, Turnaround time of each process and
Average Turnaround time.
V. T EST P ERFORMED ON T OOL
After developing the tool all the scheduling algorithms were
executed to test the accuracy of the tool. Processes with their
names and burst time were entered using the Add Process
dialog box. Table 1 represents the one sample test data that
we used to test all the scheduling algorithms. Priority field
was only used for the Priority Scheduling. A time Slice of
Fig. 2. Left Pane to enter and display the details of running processes entered
2 unit was used for round robin algorithm. The outcomes
of the different parameters as calculated by the tool are also
summarized in Table 2. The execution of Round Robin, FCFS,
SJF are shown in figure 5, figure 6, and figure 7 respectively.
Fig. 3. Add Process Dialog Box to enter a process in the system. User can
add Process Name and CPU Burst Time required by process to complete its
execution.
Fig. 5. Execution of Round Robin Scheduling Algorithm. Depiction of Gantt
chart in the centre pane. All the performance criteria are calculated and
displayed in the bottom pane.
Fig. 4. Add Process Dialog Box for the Priority Scheduling. It has an extra
field to attach a priority with process.
VI. C ONCLUSION AND F UTURE S COPE
Operating system is a mandatory course taught to CS
students. CPU scheduling is a important part of designing
an operating system. Students find it difficult to grasp the
basic concepts and difference between various scheduling
algorithms. Learning from text book has been made interesting
using visual tools. We proposed a Java desktop application that
simulates the execution of processes on the basis of different
scheduling algorithms. User can enter process runtime details
in the system and can visually see the execution of processes
applying a particular scheduling scheme. Multicolored Gantt Fig. 6. Execution of FCFS Scheduling Algorithm
chart is used for better understanding. We tested the applica-
tion for its accurate result. We have shown the application to
TABLE I
P ROCESSES AND THEIR RUNTIME INFORMATION
Process Name Process Burst Time Priority
P1 7 3
P2 4 1
P3 1 3
P4 4 4
P5 9 2
P6 3 5
TABLE II
C ALCULATION OF VARIOUS PARAMETERS AS SHOWN BY THE
APPLICATION DEVELOPED
Algorithm Tested Average waiting time Average Turnaround time
FCFS 10.33 17.83
SJF 7.67 15.17
Fig. 7. Execution of SJF Scheduling Algorithm
Round Robin 11.17 18.67
Priority 12.67 20.17
students and they find it interesting to use and learn.
In future we will find out how effectively the tool can prove
to be beneficial to the students. We plan to extend the tools
applying more critical scheduling aspects like feedback queue
and multilevel feedback queue. We also plan to add more
features of operating system mainly the concepts of memory
management like paging, segmentation and fragmentation. The
tool is available with the author and can be reached out by
contacting at the email id.
R EFERENCES
[1] Abraham Silberschatz, Peter B. Galvin, Greg Gagne –
Operating System Concepts, Sixth Edition, John Wiley
& Sons (2003).
[2] Stallings – Operating Systems, Sixth Edition, Pearson
Education India.
[3] Osman Balci et al, ”Animations to Assist Learning Some
Key Computer Science Topics”, ACM Journal on Edu-
cational Resources in Computing, Vol. 1, No.2, August
2002.
[4] Grissom, S., McNally, M., and Naps, T., ”Algorithm
Visualization in CS Education: Comparing Levels of
Student Engagement”, Proceedings of the 2003 ACM
Symposium on Software Visualization, pp. 87-94.
[5] Kevin K. Leung, Du Zhang ”Animation of Linux Proces-
sor Scheduling Algorithm”, Proceedings of the Seventh
IEEE International Symposium on Multimedia (ISM’05).
[6] Sukanya Suranauwarat ”A CPU Scheduling Algorithm
Simulator”, 37th ASEE/IEEE Frontiers in Education
Conference.
[7] Herbert Schildt – Java: The Complete Reference, Sev-
enth Edition, McGraw Hill Professional, McGraw Hill
Professional.
[8] Marc Loy, Robert Eckstein – Java Swings, O’Reilly
Media Inc. (2002).
[9] [Link]
[10] [Link]
[11] [Link]