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

LAB5

This lab exercise focuses on implementing Shortest Job Next (SJN) and Round Robin scheduling algorithms in C++. Students are required to create classes for each algorithm with functions to schedule processes, calculate average waiting and turnaround times, and display results in a Gantt chart. Testing with specified processes and time slices is necessary, and students must submit their source code and lab report by the deadline.

Uploaded by

obliepius14
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

LAB5

This lab exercise focuses on implementing Shortest Job Next (SJN) and Round Robin scheduling algorithms in C++. Students are required to create classes for each algorithm with functions to schedule processes, calculate average waiting and turnaround times, and display results in a Gantt chart. Testing with specified processes and time slices is necessary, and students must submit their source code and lab report by the deadline.

Uploaded by

obliepius14
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

UNIVERSITY OF GHANA

FACULTY OF ENGINEERING SCIENCES


DEPARTMENT OF COMPUTER ENGINEERING
CPEN 307: OPERATING SYSTEMS
LAB 5 – Deadline: 27th January 2025

Exercise 1
Implementing Shortest Job Next and Round Robin Algorithms
In your previous lab, you implemented the First come first serve algorithm. In this lab, we will
consider the Round Robin and Shortest Job Next scheduling algorithms. We will consider only
processes with same arrival times and different arrival times that do not require any I/O burst
cycles.

1. Create separate classes for the Round Robin and Shortest Job Next (SJN) scheduling
algorithms. Each class should have at least these 3 functions:
a. schedule() : This function should receive as input the CPU burst times and arrival
times of the processes and order them in a queue based on the scheduling algorithm.
Note: inputs should come from a user. The same schedule function should be able
to schedule processes with different arrival times and processes with the same
arrival times.
b. averageWaitingTime() : This function should calculate the average waiting time
of the processes. You are free to create different averageWaitingTime() functions
for the different scheduling algorithms. Eg; RRaverageWaitingTime(),
SJNaverageWaitingTime( ), etc.
c. averageTurnaroundTime() : This function should receive as input the data from
the schedule( ) function and calculate the average turnaround time of the processes.

2. Display the scheduling order of your processes in a Gannt chart. Display the average
waiting time and average turnaround time for the processes. Create a display() function to
display the Gantt chart, average waiting and average turnaround times.

NB: Your code should work for all use cases: same arrival times or different arrival times. If two
or more processes have the same arrival times, the process inputted by the user first has precedence
over the others.
Testing your scheduling algorithms
Test your round robin scheduling algorithm with the example in Table 1. Use time slices of 10ms,
15ms, 20ms and 25ms. Based on your analysis for each time slice, discuss the effect of time slice
on average turnaround time and average waiting time.

Table 1: Processes to be scheduled with Round Robin

Process CPU Burst time (ms) Arrival time (ms)

P1 53 0.0

P2 17 2.0

P3 68 4.0

P4 24 5.0

Test your SJN scheduling algorithm with the example in Table 2 for when all processes arrive at
time 0 ms and for when they arrive at different times as indicated in the table.
Table 2: Processes to be scheduled with SJN

Process CPU Burst time (ms) Arrival time (ms)

P1 7 0.0

P2 4 2.0

P3 1 4.0

P4 4 5.0

Deliverables
Show your progress to the teaching assistant at the end of the lab session for partial grades. It is
compulsory to finish implementing the round robin algorithm at the end of the session. Show the
T.A your results for at least one time slice at the end of the lab session for the partial grades.

Submit your source code (.cpp files) for the exercise together with your lab report in a folder to
the teaching assistant by the stated deadline. Your report should include screenshots of your
results.

Your folder should be named: indexnumber_lastname_lab5

You might also like