0% found this document useful (0 votes)
24 views36 pages

Os Cpu Scheduling

The document presents a project report on 'CPU Scheduling Simulation' conducted by Kedharnadh K and Sanjana Reddy Sangam under the guidance of Dr. D. Viji at SRM Institute of Science and Technology. It outlines the implementation and analysis of various CPU scheduling algorithms, including their performance metrics and optimization techniques. The project aims to enhance understanding of CPU scheduling's impact on system efficiency and resource allocation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views36 pages

Os Cpu Scheduling

The document presents a project report on 'CPU Scheduling Simulation' conducted by Kedharnadh K and Sanjana Reddy Sangam under the guidance of Dr. D. Viji at SRM Institute of Science and Technology. It outlines the implementation and analysis of various CPU scheduling algorithms, including their performance metrics and optimization techniques. The project aims to enhance understanding of CPU scheduling's impact on system efficiency and resource allocation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

lOMoARcPSD|52496367

OS Report

Big Data Analytics (SRM Institute of Science and Technology)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Fulera Himanshu ([email protected])
lOMoARcPSD|52496367

CPU Scheduling Simulator

Submitted by

Kedharnadh K [RA2211003011694]
Sanjana Reddy Sangam [RA2211003011710]

Under the Guidance of

Dr. D. VIJI
Assistant Professor, Department of Computing Technologies

In partial satisfaction of the requirements for the degree of

BACHELORS OF TECHNOLOGY
in
COMPUTER SCIENCE ENGINEERING

SCHOOL OF COMPUTING

COLLEGE OF ENGINEERING AND TECHNOLOGY


SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
KATTANKULATHUR - 603203

NOVEMBER 2023

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

SRM INSTITUTION OF SCIENCE AND TECHNOLOGY


KATTANKULATHUR-603203

BONAFIDE CERTIFICATE

Certified that this B. Tech project report titled “CPU Scheduling Simulation” is

the bonafide work of Mr. Kedharnadh K [Reg. No. RA2211003011694] and Ms.

Sanjana Reddy Sangam [Reg. No. RA2211003011710] who carried out the project

work under my supervision. Certified further, that to the best of my knowledge the

work reported herein does not form part of any other thesis or dissertation on the

basis of which a degree or award was conferred on an earlier occasion for this or

any other candidate.

SIGNATURE HEAD OF THE DEPARTMENT


Faculty In-Charge Dr. M. Pushpalatha
Dr.D.VIJI Professor and Head
Assistant Professor Department of Computing Technologies
Department of Computing Technologies SRM Institute of Science and Technology
SRM Institute of Science and Technology

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

ABSTRACT

The CPU Scheduling Simulation Project focuses on the


implementation and analysis of various CPU scheduling
algorithms including FCFS, SJF, RR, Priority Scheduling (both
preemptive and non-preemptive). The project offers a user-
friendly graphical interface for interactive visualization, enabling
users to input custom processes and modify algorithm parameters.
Through extensive simulations, the project evaluates the
performance of these algorithms based on metrics such as average
waiting time, turnaround time, throughput, and CPU utilization.
Predefined workload scenarios are utilized to rigorously test the
algorithms under different conditions, allowing for a
comprehensive understanding of their behavior. The project also
explores optimization techniques, scalability, and impact analysis,
providing valuable insights for selecting appropriate scheduling
strategies and enhancing system efficiency.

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

ACKNOWLEDGEMENT

We express our heartfelt thanks to our honorable Vice Chancellor


Dr. C. MUTHAMIZHCHELVAN, for being the beacon in all our
endeavors.

We would like to express my warmth of gratitude to our Registrar


Dr. S. Ponnusamy, for his encouragement.

We express our profound gratitude to our Dean (College of


Engineering and Technology) Dr. T. V. Gopal, for bringing out novelty
in all executions.

We would like to express my heartfelt thanks to Chairperson, School


of Computing Dr. Revathi Venkataraman, for imparting confidence
to complete my course project.

We extend our gratitude to our HoD Dr. M. Pushpalatha, Professor,


Computing Technologies and my Departmental faculties for their
Support.

We are highly thankful to our Course project Faculty Dr. D. Viji,


Assistant Professor, Department of Computing Technologies, for
his/her assistance, timely suggestion and guidance throughout the
duration of this course project.

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

TABLE OF CONTENTS

CH CONTENTS P

APT A

ER G

NO E

O
1 INTRODUCTI 5
ON
1.1 Motivation
1.2 Objective
1.3 Problem

Statement
1.4 Challenges
2 LITERATURE 7
SURVEY
3 REQUIREME 9
NT ANALYSIS
4 ARCHITECTU 1
RE & DESIGN 4
5 CODE 1
6 SNIPPETS 6
OUTPUT
2

9
CONCLUSION 3
7 1
REFERENCES 3
8
4

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

1. INTRODUCTION

1.1 Motivation:

In the ever-evolving landscape of computing, the efficient management of central processing


unit (CPU) resources remains an enduring challenge and a catalyst for innovation. The
motivation behind this CPU Scheduling Simulation project is deeply rooted in the recognition
of CPU scheduling as a critical cornerstone of modern operating systems. The need for
optimal resource utilization, enhanced system responsiveness, and fair allocation of
computing power has never been more relevant, given the increasing diversity and
complexity of software workloads in today's computing environments.

The real-world impact of CPU scheduling inefficiencies can be felt in various domains, from
server farms striving to deliver swift responses to millions of user requests to embedded
systems managing critical tasks in healthcare and automotive applications. This project aims
to address these challenges by delving into the heart of CPU scheduling, seeking to unveil the
dynamics of scheduling algorithms and their far-reaching effects on system performance.

1.2 Objective:

The primary objective of this CPU Scheduling Simulation project is to gain a profound
understanding of CPU scheduling algorithms and their practical implications in the world of
5

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

operating systems. We aspire to achieve this by conducting in-depth research, implementing a


comprehensive simulator, and rigorously analyzing the performance of various scheduling
algorithms. The project's objectives include:

Exploring and simulating a range of CPU scheduling algorithms.


Analyzing and comparing the performance of these algorithms through data-driven metrics.
Gaining insights into the trade-offs associated with different scheduling policies.
Providing a foundation for informed decision-making in selecting scheduling algorithms for
diverse system requirements and workloads.

1.3 Problem Statement:

CPU scheduling is a quintessential problem in the field of operating systems. The problem
statement can be encapsulated in the question of how to effectively allocate CPU time to
processes to ensure optimal system performance and resource utilization. The challenge lies
in selecting the most suitable scheduling algorithm for a given scenario, taking into account
factors such as turnaround time, response time, fairness, and system throughput. This project
seeks to address the problem statement by simulating and evaluating various scheduling
algorithms, ultimately offering insights into their strengths, weaknesses, and real-world
applicability.

1.4 Challenges:

The challenges encountered in this project are multifaceted. Developing a CPU scheduling
simulator that accurately emulates real-world scenarios and processes is a complex task. It
involves handling issues related to process generation, time-sharing, and data collection, all
while ensuring that the simulation reflects the dynamic nature of modern operating systems.
Additionally, the selection and implementation of scheduling algorithms pose challenges as
we aim to represent their characteristics faithfully. These challenges, along with others
encountered during the project, will be discussed in greater detail in subsequent sections,
offering a glimpse into the problem-solving and optimization processes undertaken.

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

2.LITERATURE SURVEY

The field of CPU scheduling has a rich history dating back to the inception of operating
systems. In the early days of computing, CPU scheduling was a relatively straightforward
task. Early operating systems, such as the Batch Processing System, primarily employed a
First-Come, First-Served (FCFS) scheduling policy, where processes were executed in the
order they arrived. However, as computing environments grew in complexity and diversity, it
became evident that more sophisticated scheduling mechanisms were required to optimize
system performance and resource utilization.

Over the years, a multitude of scheduling algorithms have been proposed and researched,
each with its unique set of principles and trade-offs. The historical perspective of CPU
scheduling provides valuable insights into the evolution of scheduling policies, underscoring
the need for flexibility and adaptability in managing CPU resources.

Classic scheduling algorithms have made a profound impact on the field of operating
systems. One of the earliest and most celebrated algorithms is Shortest Job First (SJF), which
was introduced by D.E. Knuth in 1968. SJF aims to minimize the average waiting time by
selecting the process with the shortest execution time for execution next. Its strength lies in
its optimality for minimizing waiting times, but it is challenged by the difficulty of accurately
predicting execution times.

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Round Robin (RR), proposed by W. F. Clock and T. Elmaghraby in 1961, takes a time-
sharing approach, granting each process a fixed time quantum. RR ensures fairness and
responsiveness in system performance, but it may introduce overhead and potentially reduce
efficiency due to frequent context switches.

Another classic approach, Priority Scheduling, allows processes to be assigned priority


levels, with higher-priority processes being granted CPU time first. However, the
effectiveness of priority scheduling hinges on the accurate determination and dynamic
adjustment of priorities, which can be a challenging task.

Recent developments in CPU scheduling have adapted these classic algorithms and
introduced

new policies to meet the demands of modern computing environments. Multilevel Feedback
Queue (MLFQ) scheduling, introduced by F. J. Corbato in the 1960s, has been refined over
time and continues to be relevant for managing dynamic workloads in time-sharing systems.

In addition to MLFQ, real-time operating systems have embraced specialized scheduling


algorithms like Earliest Deadline First (EDF) and Rate-Monotonic Scheduling (RMS) to
meet stringent timing constraints. These algorithms are essential for applications where
predictability and meeting deadlines are critical, such as aerospace and medical systems.

A wealth of research papers and comparative studies have been published to assess the
performance of scheduling algorithms under various scenarios. These studies have delved
into factors such as system throughput, turnaround time, response time, fairness, and
adaptability to different workloads. These comparative studies provide valuable insights into
the relative strengths and weaknesses of various scheduling policies, aiding in the selection of
the most suitable algorithm for specific system requirements.

As we look to the future, the literature survey reveals a continued interest in improving CPU
scheduling algorithms. Researchers are exploring innovative approaches, including the
integration of machine learning and artificial intelligence techniques, to predict process
behavior and make dynamic scheduling decisions. The emergence of heterogeneous and

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

multi-core systems introduces new complexities, prompting the development of novel


scheduling solutions to harness the full potential of these advanced hardware architectures.

3. REQUIREMENTS

3.1 Analysis
In a CPU Scheduling Simulation project, the analysis phase is a critical step where you
examine the results of your simulation, draw conclusions, and gain insights into the
performance of different scheduling algorithms. This phase involves interpreting the data
generated during the simulation and evaluating the impact of various scheduling policies.
Here's a breakdown of the analysis process:

1. Data Collection:
Start by collecting the data generated by your simulation. This data typically includes
information on process execution times, waiting times, turnaround times, and other relevant
metrics. Ensure that the data is well-organized and accessible for analysis.

2. Performance Metrics:
Define the performance metrics you intend to use for the evaluation of scheduling algorithms.
Common metrics include:

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Turnaround Time: The total time a process takes to complete, from arrival to termination.
Response Time: The time it takes for a process to receive its first CPU burst.
Waiting Time: The cumulative time a process spends waiting in the ready queue.
CPU Utilization: The percentage of time the CPU is actively executing a process.
3. Data Visualization:
Utilize data visualization tools and techniques to present the simulation results in a clear and
understandable manner. Create plots, charts, graphs, and tables to visualize the performance
of different scheduling algorithms. Visual representations can make it easier to identify trends
and patterns.

4. Comparative Analysis:
Compare the performance of various scheduling algorithms based on the collected data.
Analyze how different algorithms perform in terms of the defined metrics. Pay attention to
variations in turnaround times, response times, and other critical parameters.

5. Identifying Trade-Offs:
Identify the trade-offs associated with each scheduling algorithm. For instance, some
algorithms may excel in minimizing response times but at the cost of potentially higher
waiting times. Evaluate which trade-offs are acceptable for different system requirements and
workloads.

6. Real-World Relevance:
Discuss the practical implications of your findings. Consider how the performance of
scheduling algorithms aligns with real-world scenarios and system types. Explore the impact
on user experience and system efficiency.

7. Insights and Conclusions:


Based on your analysis, draw insights and conclusions about the effectiveness of each
scheduling algorithm. Discuss which algorithms are well-suited for specific use cases and
workloads. Highlight the strengths and weaknesses of each policy.

8. Recommendations:

10

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Offer recommendations for the selection of scheduling algorithms based on your findings.
Consider the trade-offs and priorities of different systems when suggesting the most suitable
algorithm for specific applications.

9. Limitations:
Acknowledge the limitations of your simulation and analysis. Discuss factors that may have
affected the results, such as simplifications in the simulation model, assumptions made, or
constraints of the software and hardware used.

10. Future Work:


Suggest areas for future research or improvements in CPU scheduling. Consider avenues for
refining scheduling policies, incorporating machine learning techniques, or addressing the
challenges posed by emerging hardware architectures.

11. Reporting and Documentation:


Ensure that your analysis is well-documented in your project report. Provide clear and
concise explanations, supported by visual representations and data, to make your analysis
accessible to

readers.

3.2 Hardware Requirements:

Computer System: You will need a computer system with sufficient processing power and
memory to run the CPU scheduling simulation software and associated tools efficiently. The
specific hardware requirements may vary based on the complexity of your simulation.

Storage Space: Adequate storage space is required to store the simulation program, data, and
any generated logs or results.

Input Devices: A standard keyboard and mouse or other input devices for interacting with the
simulation software.

11

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

3.3 Software Requirements:

Operating System: You need an operating system compatible with the simulation software
and programming tools you plan to use. Popular choices include Windows, Linux, or macOS.

Programming Language: Depending on your preference, you should choose a programming


language for implementing the CPU scheduling simulation. Common choices include Python,
C++, or Java. Ensure that the chosen language provides sufficient support for data structures
and system interaction.

Development Environment: Select an integrated development environment (IDE) or code


editor suitable for your chosen programming language. IDEs such as Visual Studio Code,
PyCharm, or Eclipse can facilitate code development and debugging.

Simulation Libraries or Frameworks: If available, use simulation libraries or frameworks that


can streamline the development of the simulation. For example, if you are implementing a
discrete-event simulation, you might consider using SimPy for Python or other relevant
libraries.

Data Visualization Tools: To present your simulation results effectively, consider using data
visualization tools and libraries such as Matplotlib for Python or ggplot2 for R.

Documentation Tools: Utilize documentation tools or formats to create and maintain project
documentation, such as Markdown, LaTeX, or Microsoft Word.

Project-Specific Requirements:

Clear Objectives: Define clear objectives for your CPU scheduling simulation project.
Determine what specific aspects of CPU scheduling you intend to explore and the goals you
aim to achieve.

Scheduling Algorithms: Decide which scheduling algorithms you want to simulate, as well as
their specific parameters and characteristics.
12

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Data Generation: Specify how you will generate or acquire the data needed for the
simulation. This includes defining the characteristics of processes, their arrival times, burst
times, and any other relevant attributes.

Simulation Logic: Define the logic and rules for how the simulation will progress, including
how scheduling decisions will be made, time quantum management (if applicable), and how
processes will transition between states.

Performance Metrics: Determine the performance metrics you will use to evaluate the
effectiveness of different scheduling algorithms. Common metrics include turnaround time,
response time, waiting time, and CPU utilization.

Simulation Output: Decide on the format and presentation of the simulation output. This may
include generating logs, reports, graphs, or other visual representations of the simulation
results.

User Interface (Optional): If your project includes a user interface for interaction or
visualization, define the requirements for this component.

Documentation: Plan for comprehensive documentation, including project reports, user


manuals, and code comments to ensure that the simulation is well-documented and
understandable.

Testing and Validation: Establish a testing plan to validate the accuracy and reliability of the
simulation. This may involve comparing the simulation results with analytical or theoretical
expectations.

Project Timeline: Develop a project timeline that outlines the key milestones, tasks, and
deadlines for the project, including the development, testing, and documentation phases.

13

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Resources: Identify any external resources, research papers, textbooks, or reference materials
that will be crucial for understanding scheduling algorithms and implementing the
simulation.

4. ARCHITECTURE AND DESIGN

The architecture and design phase of our CPU Scheduling Simulation project is a pivotal step in
shaping the structure and components of the simulation. It serves as the blueprint for the
implementation, guiding the development process and ensuring that the simulation accurately
models the behavior of scheduling algorithms. In this section, we provide an in-depth overview of
the architectural design and the key components that constitute our simulation.

4.1 System Architecture


14

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

At the highest level, our CPU Scheduling Simulation can be visualized as a multi-component
system where processes traverse through various states and interact with the central scheduling
component. The following components constitute the system architecture:

Scheduler Component: The scheduler is the core component responsible for making scheduling
decisions. It manages the allocation of CPU time to processes and selects the next process to run
based on the chosen scheduling algorithm. The scheduler component plays a pivotal role in
determining system performance.

Process Component: Processes are central to our simulation. Each process is represented as an
entity with attributes such as arrival time, burst time, priority (if applicable), and state transitions.
Processes move between states, including "ready," "running," and "terminated," in response to
scheduling decisions and time progression.

Queue Management: In cases where scheduling algorithms involve ready queues (e.g., Round
Robin or Priority Scheduling), a component is responsible for managing these queues. This
includes handling the insertion of processes, removal of processes upon execution, and
prioritization.

Clock or Timer Component: Time management is an integral part of our simulation. We employ a
simulation clock to track the progression of time, and a timer component enforces the scheduling
of processes based on defined time quanta or priorities.

4.2 Interaction and Data Flow


The interaction and data flow between these components are essential for the functioning of the

simulation. Key aspects of this interaction include:

Processes enter the system and are managed by the Process Component. These processes
transition between states, with the scheduler making scheduling decisions based on defined
policies.

15

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

The Scheduler Component communicates with the Process Component to determine the next
process to run. This communication involves the selection of a process from the ready queue
based on the scheduling algorithm's criteria.

Data, including process attributes and scheduling decisions, flows between components to update
the state of the system. As processes execute, the simulation clock advances, and the system
continues to progress.

4.3 Algorithms and Policies


Our simulation will incorporate various CPU scheduling algorithms, each with its distinct
characteristics and parameters. These algorithms will be integrated into the Scheduler
Component, specifying how they will select processes and allocate CPU time. We will ensure that
the simulation allows for the easy configuration and activation of different algorithms, enabling
us to evaluate their performance.

4.4 User Interface (Optional)


While not a mandatory component, our simulation project may include a user interface to
facilitate interaction and visualization. The user interface design will depend on the project's
specific requirements and may include features such as the input of process data, visualization of
scheduling decisions, and reporting of simulation results.

4.5 Simulation Logic


The simulation logic will define how the system progresses over time. It will encompass the
generation of processes, their transition between states, the execution of processes, and the
management of the simulation clock. The simulation logic will adhere to the principles of the
chosen scheduling algorithms, ensuring that the behavior accurately reflects their operation.

5. CODE SNIPPETS

5.1 First Come First Serve (FCFS)

import java.util.Collections;

16

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

import java.util.List;

public class FirstComeFirstServe extends CPUScheduler


{
@Override
public void process()
{
Collections.sort(this.getRows(), (Object o1, Object o2) -> {
if (((Row) o1).getArrivalTime() == ((Row) o2).getArrivalTime())
{
return 0;
}
else if (((Row) o1).getArrivalTime() < ((Row) o2).getArrivalTime())
{
return -1;
}
else
{
return 1;
}
});

List<Event> timeline = this.getTimeline();

for (Row row : this.getRows())


{
if (timeline.isEmpty())
{
timeline.add(new Event(row.getProcessName(), row.getArrivalTime(),

row.getArrivalTime() + row.getBurstTime()));
}
else
{

17

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Event event = timeline.get(timeline.size() - 1);


timeline.add(new Event(row.getProcessName(), event.getFinishTime(),
event.getFinishTime() + row.getBurstTime()));
}
}

for (Row row : this.getRows())


{
row.setWaitingTime(this.getEvent(row).getStartTime() - row.getArrivalTime());
row.setTurnaroundTime(row.getWaitingTime() + row.getBurstTime());
}
}
}

5.2 Shortest Job First (SJF)

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ShortestJobFirst extends CPUScheduler


{
@Override
public void process()
{
Collections.sort(this.getRows(), (Object o1, Object o2) -> {
if (((Row) o1).getArrivalTime() == ((Row) o2).getArrivalTime())
{
return 0;

}
else if (((Row) o1).getArrivalTime() < ((Row) o2).getArrivalTime())
{
return -1;

18

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

}
else
{
return 1;
}
});

List<Row> rows = Utility.deepCopy(this.getRows());


int time = rows.get(0).getArrivalTime();

while (!rows.isEmpty())
{
List<Row> availableRows = new ArrayList();

for (Row row : rows)


{
if (row.getArrivalTime() <= time)
{
availableRows.add(row);
}
}

Collections.sort(availableRows, (Object o1, Object o2) -> {


if (((Row) o1).getBurstTime() == ((Row) o2).getBurstTime())
{
return 0;
}
else if (((Row) o1).getBurstTime() < ((Row) o2).getBurstTime())
{
return -1;

}
else
{
return 1;
19

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

}
});

Row row = availableRows.get(0);


this.getTimeline().add(new Event(row.getProcessName(), time, time +
row.getBurstTime()));
time += row.getBurstTime();

for (int i = 0; i < rows.size(); i++)


{
if (rows.get(i).getProcessName().equals(row.getProcessName()))
{
rows.remove(i);
break;
}
}
}

for (Row row : this.getRows())


{
row.setWaitingTime(this.getEvent(row).getStartTime() - row.getArrivalTime());
row.setTurnaroundTime(row.getWaitingTime() + row.getBurstTime());
}
}
}

5.3 Round Robin Scheduling

import java.util.Collections;

20

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RoundRobin extends CPUScheduler


{
@Override
public void process()
{
Collections.sort(this.getRows(), (Object o1, Object o2) -> {
if (((Row) o1).getArrivalTime() == ((Row) o2).getArrivalTime())
{
return 0;
}
else if (((Row) o1).getArrivalTime() < ((Row) o2).getArrivalTime())
{
return -1;
}
else
{
return 1;
}
});

List<Row> rows = Utility.deepCopy(this.getRows());


int time = rows.get(0).getArrivalTime();
int timeQuantum = this.getTimeQuantum();

while (!rows.isEmpty())

{
Row row = rows.get(0);
int bt = (row.getBurstTime() < timeQuantum ? row.getBurstTime() : timeQuantum);
this.getTimeline().add(new Event(row.getProcessName(), time, time + bt));

21

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

time += bt;
rows.remove(0);

if (row.getBurstTime() > timeQuantum)


{
row.setBurstTime(row.getBurstTime() - timeQuantum);

for (int i = 0; i < rows.size(); i++)


{
if (rows.get(i).getArrivalTime() > time)
{
rows.add(i, row);
break;
}
else if (i == rows.size() - 1)
{
rows.add(row);
break;
}
}
}
}

Map map = new HashMap();

for (Row row : this.getRows())


{
map.clear();

for (Event event : this.getTimeline())

{
if (event.getProcessName().equals(row.getProcessName()))
{
if (map.containsKey(event.getProcessName()))
22

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

{
int w = event.getStartTime() - (int) map.get(event.getProcessName());
row.setWaitingTime(row.getWaitingTime() + w);
}
else
{
row.setWaitingTime(event.getStartTime() - row.getArrivalTime());
}

map.put(event.getProcessName(), event.getFinishTime());
}
}

row.setTurnaroundTime(row.getWaitingTime() + row.getBurstTime());
}
}
}

5.4 Priority Scheduling (Preemptive)

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PriorityPreemptive extends CPUScheduler


{
@Override

public void process()


{
Collections.sort(this.getRows(), (Object o1, Object o2) -> {
if (((Row) o1).getArrivalTime() == ((Row) o2).getArrivalTime())

23

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

{
return 0;
}
else if (((Row) o1).getArrivalTime() < ((Row) o2).getArrivalTime())
{
return -1;
}
else
{
return 1;
}
});

List<Row> rows = Utility.deepCopy(this.getRows());


int time = rows.get(0).getArrivalTime();

while (!rows.isEmpty())
{
List<Row> availableRows = new ArrayList();

for (Row row : rows)


{
if (row.getArrivalTime() <= time)
{
availableRows.add(row);
}
}

Collections.sort(availableRows, (Object o1, Object o2) -> {


if (((Row) o1).getPriorityLevel()== ((Row) o2).getPriorityLevel())

{
return 0;
}
else if (((Row) o1).getPriorityLevel() < ((Row) o2).getPriorityLevel())
24

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

{
return -1;
}
else
{
return 1;
}
});

Row row = availableRows.get(0);


this.getTimeline().add(new Event(row.getProcessName(), time, ++time));
row.setBurstTime(row.getBurstTime() - 1);

if (row.getBurstTime() == 0)
{
for (int i = 0; i < rows.size(); i++)
{
if (rows.get(i).getProcessName().equals(row.getProcessName()))
{
rows.remove(i);
break;
}
}
}
}

for (int i = this.getTimeline().size() - 1; i > 0; i--)


{
List<Event> timeline = this.getTimeline();

if (timeline.get(i - 1).getProcessName().equals(timeline.get(i).getProcessName()))
{
timeline.get(i - 1).setFinishTime(timeline.get(i).getFinishTime());
timeline.remove(i);
25

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Map map = new HashMap();

for (Row row : this.getRows())


{
map.clear();

for (Event event : this.getTimeline())


{
if (event.getProcessName().equals(row.getProcessName()))
{
if (map.containsKey(event.getProcessName()))
{
int w = event.getStartTime() - (int) map.get(event.getProcessName());
row.setWaitingTime(row.getWaitingTime() + w);
}
else
{
row.setWaitingTime(event.getStartTime() - row.getArrivalTime());
}

map.put(event.getProcessName(), event.getFinishTime());
}
}

row.setTurnaroundTime(row.getWaitingTime() + row.getBurstTime());
}}}

5.5 Priority Scheduling (Non - Preemptive)

import java.util.ArrayList;

26

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

import java.util.Collections;
import java.util.List;

public class PriorityNonPreemptive extends CPUScheduler


{
@Override
public void process()
{
Collections.sort(this.getRows(), (Object o1, Object o2) -> {
if (((Row) o1).getArrivalTime() == ((Row) o2).getArrivalTime())
{
return 0;
}
else if (((Row) o1).getArrivalTime() < ((Row) o2).getArrivalTime())
{
return -1;
}
else
{
return 1;
}
});

List<Row> rows = Utility.deepCopy(this.getRows());


int time = rows.get(0).getArrivalTime();

while (!rows.isEmpty())
{
List<Row> availableRows = new ArrayList();

for (Row row : rows)


{
if (row.getArrivalTime() <= time)

27

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

{
availableRows.add(row);
}
}

Collections.sort(availableRows, (Object o1, Object o2) -> {


if (((Row) o1).getPriorityLevel()== ((Row) o2).getPriorityLevel())
{
return 0;
}
else if (((Row) o1).getPriorityLevel() < ((Row) o2).getPriorityLevel())
{
return -1;
}
else
{
return 1;
}
});

Row row = availableRows.get(0);


this.getTimeline().add(new Event(row.getProcessName(), time, time +
row.getBurstTime()));
time += row.getBurstTime();

for (int i = 0; i < rows.size(); i++)


{
if (rows.get(i).getProcessName().equals(row.getProcessName()))
{
rows.remove(i);
break;

}
}

28

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

for (Row row : this.getRows())


{
row.setWaitingTime(this.getEvent(row).getStartTime() - row.getArrivalTime());
row.setTurnaroundTime(row.getWaitingTime() + row.getBurstTime());
}
}
}

6. OUTPUT

29

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Fig. 6.1

Fig. 6.2

Fig. 6.3

Fig. 6.4

Screenshot Representations:
30

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

In our comprehensive CPU Scheduling Simulation project, we present crucial visualizations


encapsulating the entire simulation process. Figure 6.1 provides a holistic overview of the CPU
scheduling output, showcasing the intricate details of our analysis. Figure 6.2 zooms in on the
round-robin (RR) scheduling algorithm, capturing the dynamic nature of time quantum
adjustments through a pop-up interface. Figure 6.3 illustrates the Gantt chart, offering a visual
representation of the scheduled processes and their execution timelines.

Furthermore, Figure 6.4 meticulously displays the calculated average waiting time and average
turnaround time after the scheduling process. These figures serve as pivotal metrics, reflecting the
efficiency and responsiveness of the system under different scheduling algorithms. By
incorporating these visualizations, our project report provides a comprehensive and detailed
insight into the simulation results, enhancing the readers' understanding of the complex dynamics
of CPU scheduling and its impact on system performance.

31

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

7. CONCLUSION
In this section, we provide a concise summary of the CPU Scheduling Simulation project,
highlighting the major achievements and insights gained throughout the project's lifecycle.

7.1 Objectives and Achievements

Our project began with clear objectives in mind, aiming to explore the dynamic world of CPU
scheduling and the performance of various scheduling algorithms. We are pleased to report that
we have achieved these objectives effectively. The project allowed us to gain a comprehensive
understanding of CPU scheduling and its real-world implications.

Through the course of this project, we implemented a CPU scheduling simulation that faithfully
emulates the behavior of multiple scheduling algorithms. The simulator successfully
demonstrated the operation of algorithms such as Round Robin, First-Come, First-Served (FCFS),
and Priority Scheduling, among others. The results obtained from the simulation provided
valuable insights into the strengths and weaknesses of these algorithms under various scenarios.

7.2 Key Findings and Insights

Our analysis and evaluation of the simulation results have yielded several key findings and
insights. These findings include:

Algorithm Performance: We observed that the performance of scheduling algorithms varies


depending on the specific workload and system characteristics. While Round Robin exhibited
fairness and responsiveness, Priority Scheduling excelled in managing high-priority tasks. FCFS,
although simple, may lead to longer waiting times in certain scenarios.

Trade-Offs: It became apparent that there are trade-offs associated with different scheduling
algorithms. For example, algorithms optimized for minimizing response times might sacrifice
overall system throughput. Understanding these trade-offs is crucial when selecting the most
suitable algorithm for a particular application.

Real-World Relevance: The findings from our simulation align closely with real-world scenarios.
The insights gained through this project have direct applications in diverse computing
environments, from server farms handling multiple user requests to embedded systems managing
time-sensitive tasks.

7.3 Future Directions

Our project has illuminated the intricate world of CPU scheduling, but it also points to several
areas for future research and enhancement. Some potential avenues for further exploration
include:

32

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

Machine Learning Integration: Exploring the integration of machine learning techniques to


predict process behavior and make dynamic scheduling decisions. This could lead to more
adaptive and intelligent scheduling policies.

Heterogeneous Systems: Investigating the challenges posed by heterogeneous and multi-core


systems and developing scheduling solutions to harness the full potential of such hardware
architectures.

Optimization and Real-Time Systems: Delving into the optimization of existing scheduling
algorithms and their adaptability to real-time systems with stringent timing constraints.

7.4 Conclusion and Impact

In conclusion, our CPU Scheduling Simulation project has provided valuable insights into the
world of CPU scheduling and its impact on system performance. We have successfully achieved
our project objectives, offering a comprehensive understanding of scheduling algorithms and their
practical implications.

The knowledge gained from this project will serve as a valuable resource for system
administrators, software developers, and researchers in the field of operating systems. By
shedding light on the nuances of CPU scheduling, we aim to contribute to the ongoing
advancement of efficient resource allocation and system performance.

We express our gratitude to all those who supported us during the project's development and
analysis phases. Their contributions have been invaluable in making this project a success.

33

Downloaded by Fulera Himanshu ([email protected])


lOMoARcPSD|52496367

8. REFERENCES

IEEE Website:
https://www.computer.org/csdl/proceedingsarticle/fie/2007/04417885/12OmNyFCvXC

Research Gate:
https://www.researchgate.net/publication/4305451_A_CPU_scheduling_algorithm_simulator

34

Downloaded by Fulera Himanshu ([email protected])

You might also like