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

LAB #5 CPU Scheduling Algorithms-1: Objective Theory

This document discusses CPU scheduling algorithms and describes two algorithms: First Come First Serve (FCFS) and Shortest Job First (SJF). It defines key scheduling criteria like CPU utilization, throughput, turnaround time, waiting time, and response time. For the lab, students will write programs to simulate FCFS and SJF scheduling (both preemptive and non-preemptive) by taking CPU burst times as input and calculating metrics like average waiting time. They will display the results in a text-based Gantt chart.

Uploaded by

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

LAB #5 CPU Scheduling Algorithms-1: Objective Theory

This document discusses CPU scheduling algorithms and describes two algorithms: First Come First Serve (FCFS) and Shortest Job First (SJF). It defines key scheduling criteria like CPU utilization, throughput, turnaround time, waiting time, and response time. For the lab, students will write programs to simulate FCFS and SJF scheduling (both preemptive and non-preemptive) by taking CPU burst times as input and calculating metrics like average waiting time. They will display the results in a text-based Gantt chart.

Uploaded by

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

SWE-204L: OPERATING SYSTEM SSUET/QR/114

LAB #5

CPU Scheduling Algorithms-1


Objective
To simulate CPU Scheduling Algorithms. (First Come First Serve, Shortest Job First).

Theory
Scheduling is the task of operating system in which processes are given access to system
resources. Scheduling is a fundamental operating system function that determines which
process run, when there are multiple processes in ready queue. CPU scheduling is important
because it impacts resource utilization and other performance parameters.

Scheduling Criteria
Different CPU scheduling algorithms have different properties and may favor one class of
processes over another. In choosing which algorithm to use in a particular situation, we must
consider the different properties of the various algorithms.
CPU Utilization: We want to keep the CPU as busy as possible. CPU utilization may range
from 0 to 100 percent. In a real system, it should range from 40 percent (for a lightly loaded
system) to 90 percent (for a heavily used system).
Throughput: If the CPU is busy executing process, then work is being done. One calculate
of work is the number of processes that are completed per time unit, called throughput. For
long processes, this rate may be one process per hour; for short transactions, throughput
might be 10 processes per second.
Turnaround time: From the point of view of a particular process, the important criterion is
how long it takes to execute that process. The interval from the time of submission of a
process to the time of completion is the turnaround time. Turnaround time is the sum of the
periods spent waiting to get into memory, waiting in the ready queue, executing on the CPU,
and doing I/O.
Waiting Time: The CPU scheduling algorithm does not affect the amount of time during
which a procedure executes or does I/O; it affects only the amount of time that a process
spends waiting in the prepared queue. Waiting time is the sum of the periods spent waiting in
the ready queue.
Response time: In an interactive system, turnaround time may not be the best criterion.
Often, a process can produce some output fairly easy, and can continue computing new
results while earlier results are being output to the user. Thus, another measure is the time
from the submission of a request until the first response is produced. This measure, called
response time, is the time that it takes to start responding, but not the time that it takes to
output that response. The turnaround time is generally incomplete by the speed of output
device.

Scheduling Algorithms
A Process Scheduler schedules different processes to be assigned to the CPU based on
particular scheduling algorithms. There are six popular process scheduling algorithms which
we are implementing in this lab:
Operating System 27
SWE-204L: OPERATING SYSTEM SSUET/QR/114

1. First-Come, First-Served (FCFS) Scheduling


2. Shortest-Job-First (SJF) Scheduling
3. Priority Scheduling
4. Round Robin(RR) Scheduling

1. First Come First Serve (FCFS) Algorithm:


i. Start the process.
ii. Declare the array size.
iii. Get the number of elements to be inserted.
iv. Select the process that first arrived in the ready queue
v. Make the average waiting the length of next process.
vi. Start with the first process from its selection as above and let other
process to be in queue.
vii. Calculate the total number of burst time.
viii. Display the values.
ix. Stop the process.

2. Shortest Job First (SJF) Algorithm:


i. Start the process.
ii. Declare the array size.
iii. Get the number of elements to be inserted.
iv. Select the process which have shortest burst will execute first.
v. If two process have same burst length, then FCFS scheduling algorithm
used.
vi. Make the average waiting the length of next process.
vii. Start with the first process from its selection as above and let other
process to be in queue.
viii. Calculate the total number of burst time.
ix. Display the values.
x. Stop the process.

Exercise
1. Write a program which takes as an argument at least 10 CPU Brust time. Calculate CPU
utilization, average waiting time, turnaround time and response time using SJF(Non-Preemptive)
and SJF(Preemptive). Display a text-based Gantt chat on the screen.
2. Write a program which takes as an argument at least 15 CPU Brust time. Calculate CPU
utilization, average waiting time, turnaround time and response time using FCFS. Display a text-
based Gantt chat on the screen.

Operating System 28

You might also like