0% found this document useful (0 votes)
5 views6 pages

Dhaka International University: Lab Report

This lab report details the implementation of the Round Robin Scheduling Algorithm, which is a preemptive scheduling method ensuring fair CPU allocation among processes. The report includes theoretical background, source code, and observations on the algorithm's performance, highlighting the trade-offs between waiting times and context switch overhead. The conclusion emphasizes the importance of selecting an appropriate time quantum to balance responsiveness and efficiency.

Uploaded by

ehtesamzunnuryn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Dhaka International University: Lab Report

This lab report details the implementation of the Round Robin Scheduling Algorithm, which is a preemptive scheduling method ensuring fair CPU allocation among processes. The report includes theoretical background, source code, and observations on the algorithm's performance, highlighting the trade-offs between waiting times and context switch overhead. The conclusion emphasizes the importance of selecting an appropriate time quantum to balance responsiveness and efficiency.

Uploaded by

ehtesamzunnuryn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Dhaka International University

Lab Report

Operating System Lab


COURSE NO: 0613-302

Submitted to: Submitted by:

M. Morsedur Rahman Name: Ehtesam Zunnuryn

Lecturer Batch: D-83

Dhaka International University Roll: 30


Department of CSE

Date of Submission: 23 April 2025


2

Experiment No: 04
Experiment Name: Implementation of Round Robin Scheduling Algorithm
Date of Experiment: 16 April 2025

Theory:

Round Robin is a preemptive scheduling algorithm where each process gets a fixed time unit
(time quantum) for execution before being preempted and placed back in the ready queue. This
approach ensures fair CPU allocation among all processes and prevents starvation.

Key Characteristics:

 Preemptive scheduling with fixed time quantum

 Fair allocation of CPU time

 No process starvation

 Performance depends heavily on time quantum size

Formulas Used:

1. Completion Time (CT): When process finishes execution

2. Turnaround Time (TAT): CT - Arrival Time (AT)

3. Waiting Time (WT): TAT - Burst Time (BT)

4. Average Waiting Time (AWT): (ΣWT) / number of processes

Source Code:

from collections import deque

print("Round robin cpu scheduling algorithm : ")

n = int(input("Enter the number of process : "))

time_quantum = int(input("Enter the value of time quantum : "))

process = []
3

for i in range(n):

key = "P" + str(i+1)

at = int(input("Enter the arrival time of process P" + str(i+1) + ": "))

bt = int(input("Enter the burst time of process P" + str(i+1) + ": "))

process.append((key, at, bt, bt))

process.sort(key = lambda x : x[1])

time = 0

final = []

queue = deque()

i=0

while i < n or queue:

while i < n and process[i][1] <= time:

queue.append(process[i])

i += 1

if queue:

curr = queue.popleft()

key, at, bt, rbt = curr

execu_time = min(time_quantum, rbt)

time += execu_time

rbt -= execu_time

while i < n and process[i][1] <= time:

queue.append(process[i])
4

i += 1

if rbt > 0:

queue.append((key, at, bt, rbt))

else:

ct = time

tat = ct - at

wt = tat - bt

final.append((key, at, bt, ct, tat, wt))

else:

time += 1

final = sorted(final, key = lambda x : x[0][1:])

print("\nProcess | Arrival | Burst | Completion | Turn around | Waiting")

print("-" * 65)

for row in final:

print(

f"{row[0]:<7} | {row[1]:<7} | {row[2]:<5} | {row[3]:<10} | {row[4]:<11} | {row[5]:<7}"

avg_wt = sum(row[5] for row in final) / n

print(f"\nAverage waiting time : {avg_wt : .2f}")


5

Output:

Discussion:

The implemented Round Robin algorithm demonstrates several important characteristics of this
scheduling approach. The use of a time quantum ensures that no single process can monopolize
the CPU, creating a fair environment where all processes get regular execution opportunities.

In the execution phase, we observe how processes are cycled through the ready queue, each
receiving up to the specified time quantum for execution. This creates an interleaved execution
pattern where longer processes are broken into multiple chunks, while shorter processes may
complete within their first allocation. The algorithm efficiently handles new process arrivals by
adding them to the queue when they become ready.

The waiting time calculations reveal an interesting trade-off - while no process gets starved,
some may experience increased waiting times due to the overhead of frequent context
switches. This is particularly noticeable for processes with burst times just slightly longer than
the time quantum. The average waiting time serves as a key metric for evaluating the
algorithm's efficiency.
6

Conclusion:

The Round Robin algorithm provides an effective solution for time-sharing systems where
fairness and responsiveness are prioritized. While it guarantees no starvation, the choice of time
quantum significantly impacts performance - too small increases context switch overhead, while
too large may degrade response times.

You might also like