0% found this document useful (0 votes)
6 views

OS_lab_Assignment1_Report

The document details an experiment conducted at Chittagong University of Engineering & Technology focused on implementing and analyzing various CPU scheduling algorithms, including FCFS, SJF, Priority Scheduling, and Round Robin, while also proposing a new hybrid scheduling algorithm. The objectives include evaluating performance based on average runtime, waiting time, and turnaround time to determine optimal CPU utilization and process management. The proposed algorithm combines non-preemptive priority scheduling with non-preemptive SJF to enhance efficiency and responsiveness in scheduling tasks.

Uploaded by

Ashraful Islam
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)
6 views

OS_lab_Assignment1_Report

The document details an experiment conducted at Chittagong University of Engineering & Technology focused on implementing and analyzing various CPU scheduling algorithms, including FCFS, SJF, Priority Scheduling, and Round Robin, while also proposing a new hybrid scheduling algorithm. The objectives include evaluating performance based on average runtime, waiting time, and turnaround time to determine optimal CPU utilization and process management. The proposed algorithm combines non-preemptive priority scheduling with non-preemptive SJF to enhance efficiency and responsiveness in scheduling tasks.

Uploaded by

Ashraful Islam
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/ 9

Chittagong University of Engineering &

Technology

Department of Computer Science & Engineering

Experiment Name:

Implementation of existing CPU scheduling algorithms


and development of a new scheduling algorithm.

Course ID : CSE-336
Course Title : Operating System (Sessional)

Submitted To Submitted By

• Mohammed Sajidul Islam (ID:


Hasan Murad
2104095)
Assistant Professor
Dept. of CSE, CUET • Ashraf-Ul-Islam (ID: 2104096)

• Avishek Biswas (ID: 2104097)

• Nuzha Saifa Rahmat (ID: 2104098)


Lab Report: CPU Scheduling Algorithms

1.Name Of Experiment
Implementation of existing CPU scheduling algorithms and development of a new scheduling
algorithm.

2. Objectives
The primary objective of this experiment is to implement and analyze a range of CPU
Scheduling program i.e. First-Come-First-Serve (FCFS), Shortest Job First (SJF), Priority
Scheduling, and Round Robin (RR) and apply learned logic into developing a new scheduling
algorithm.

The purpose of this study is to evaluate and compare performances of each algorithm on basis
of the key metrics:

• Average Runtime (ART)


• Average Waiting Time (AWT)
• Average Turnaround Time (ATT)
By measuring and comparing these metrics, this experiment aims to determine which
scheduling algorithm offers optimal performance in terms of CPU utilization, process
management, and overall scheduling efficiency. The analysis will also highlight the trade-offs
involved in each strategy and demonstrate the potential benefits of the new approach.

3. Tools Used
• Programming Language: C++ (Recommended)
• IDE: Visual Studio Code
• Libraries: Standard C++ Libraries for vector manipulation, queues, and input/output
handling.

4.Theory – CPU Scheduling


CPU scheduling is the mechanism by which an operating system decides the order in which
processes access the CPU for execution. Since multiple processes may be in the ready state
simultaneously, the scheduler must allocate CPU time efficiently to ensure optimal system
performance. The primary objectives of CPU scheduling include maximizing CPU utilization,
minimizing process waiting time, and ensuring fair and efficient resource distribution among
all processes.

Several commonly used CPU scheduling algorithms are:


• First-Come,First-Serve(FCFS):
This is the simplest scheduling algorithm, where processes are executed in the order of
their arrival. While easy to implement, it can lead to the "convoy effect," where short
processes wait behind long ones.

• Shortest Job First (SJF):

This algorithm selects the process with the shortest burst time for execution next. It
exists in two forms:

Non-preemptive SJF: Once a process starts executing, it runs to completion.

Preemptive SJF (also known as Shortest Remaining Time First): A running process can
be preempted if a new process with a shorter burst time arrives.

• Priority Scheduling:
Each process is assigned a priority level. The scheduler selects the process with the
highest priority (typically represented by the lowest numerical value). This algorithm
can be either preemptive or non-preemptive. It may lead to starvation of lower-priority
processes unless aging is implemented.
• Round Robin (RR):
Designed for time-sharing systems, RR assigns each process a fixed time quantum.
Processes are executed in a circular queue manner, ensuring that no process is starved.
If a process doesn't complete within its time slice, it is preempted and moved to the
back of the queue.
• Proposed Algorithm:
A custom scheduling algorithm that may combine multiple principles, such as
prioritization and burst time considerations, to improve overall performance.

5. Proposed Algorithm Explanation


This proposed scheduling algorithm adopts a hybrid approach by integrating Non-Preemptive
Priority Scheduling with Non-Preemptive Shortest Job First (SJF). The core idea is to
prioritize processes based on their assigned priority values while also considering the
remaining burst time for tie-breaking among processes with the same priority level.
Specifically, the scheduler first selects the group of processes with the highest priority. Among
these processes, it then chooses the one with the shortest remaining burst time for execution.
This dual-criteria approach ensures that high-priority tasks are executed promptly, while also
minimizing overall waiting and turnaround times by favoring shorter tasks within the same
priority class.

6. Pseudocode of Proposed Algorithm


// Pseudocode: Hybrid CPU Scheduling Algorithm ( Non Preemptive Priority + Non-
Preemptive Shortest Job First (SJF))
Input:

Process list with: Process_ID, Arrival_Time, Burst_Time, Priority

Output:

Gantt Chart, Average Waiting Time (AWT),


Average Turnaround Time (ATT),

Average Response Time (ART)

BEGIN

1. Initialize:

- currentTime ← 0

- completed ← 0

- readyQueue ← empty list


- For each process:
remainingTime ← Burst_Time

isStarted ← false

2. WHILE completed < total number of processes DO:

a. Add to readyQueue all processes that have:

- Arrival_Time ≤ currentTime

- remainingTime > 0

- Not already in readyQueue


b. IF readyQueue is empty:

currentTime ← currentTime + 1

CONTINUE

c. From readyQueue:

- Select processes with the highest priority (lowest number)

- From those, choose the one with the shortest remainingTime

d. IF process is executing for the first time:

Response_Time ← currentTime - Arrival_Time


isStarted ← true
e. Execute process for 1 time unit:

remainingTime ← remainingTime - 1

currentTime ← currentTime + 1

f. IF remainingTime == 0:
Completion_Time ← currentTime

Turnaround_Time ← Completion_Time - Arrival_Time

Waiting_Time ← Turnaround_Time - Burst_Time

Mark process as completed

completed ← completed + 1

3. END WHILE

4. Calculate:
- AWT ← total Waiting_Time / total number of processes
- ATT ← total Turnaround_Time / total number of processes

- ART ← total Response_Time / total number of processes

5. Display:

- Gantt Chart showing execution order and timing

- AWT, ATT, ART

END

7.Results
Table of Arrival Time, Burst Time, and Priority
Process I.D Arrival Time(AT) Burst Time Priority

P1 6 2 3

P2 3 1 2
P3 1 7 3
P4 8 4 2
P5 6 2 4
P6 3 0 5
• CPU scheduling For FCFS
• CPU scheduling For Non-Preemptive SJF

• CPU scheduling For Preemptive SJF

• CPU scheduling For Non Preemptive Priority


• CPU scheduling For Preemptive Priority

• CPU scheduling For Round Robin


• CPU scheduling Proposed Own Algorithm

Comparison Of All CPU Scheduling Algorithms

9.Discussion
The experimental analysis indicates that the Proposed Scheduling Algorithm
demonstrates better performance compared to conventional CPU scheduling
algorithms, particularly in minimizing average waiting time and average turnaround
time. By integrating the principles of Priority Scheduling with the Shortest Remaining
Time First (SRTF) approach, the proposed algorithm achieves a more balanced and
responsive scheduling strategy.
The performance of standard algorithms can be summarized as follows:
• First Come First Serve (FCFS): While simple to implement, FCFS often results in
elevated waiting times when longer processes are scheduled before shorter ones,
leading to inefficient CPU utilization.
• Shortest Job First (SJF): This algorithm is effective at reducing turnaround time;
however, it may cause starvation of longer processes, particularly in the non-
preemptive form.
• Priority Scheduling: Though it prioritizes critical tasks, it does not account for the
burst time of processes. As a result, shorter but lower-priority processes may
experience unnecessary delays.
In contrast, the Proposed Algorithm addresses the shortcomings of these methods by
first evaluating process priority and then selecting among processes with equal
priority based on the shortest remaining burst time. This hybrid decision-making
process ensures both responsiveness to high-priority tasks and efficiency in handling
short-duration processes.
The combined consideration of priority and burst time enables the algorithm to
achieve lower average waiting and turnaround times without significantly increasing
response time or risking starvation. Therefore, it provides a more adaptable and
equitable solution for dynamic, real-world scheduling scenarios where process
characteristics can vary widely.

You might also like