Week 9 - Scheduling
Week 9 - Scheduling
TECHNOLOGY ___________________________________________________
Page - 1 - of 13
LEARNING MODULE
FOR
IT 121: INTRODUCTION TO COMPUTING
_____________________________________________________
WEEK 9
COURSE OUTLINE
Page - 2 - of 13
Overview:
Computers are everywhere: at work, at school, and at home. Computers are a primary means of local and
global communications for billions of people. Through computers, society has instant access to information from
around the globe. This module presents the knowledge you need to be computer literate. The course acquaints
students to discover different and innovative ways of using various technology and learn how computing is
applied creatively to solve problems. Students will finish this course with a solid understanding of computers,
how to use computers, and how to access information on the Web.
Objectives:
General Objective
Understand the significance of different process to be assigned to the CPU.
Discuss the different processes of scheduling algorithms.
To learn how to calculate average waiting time of different process.
Understand the process of operating system scheduling algorithms.
Familiarize themselves with the use of scheduling algorithms to the computer world.
Each chapter in this module contains a major lesson involving the introduction to computers and learn
how computing is applied creatively to solve problems. The units are characterized by continuity, and are
arranged in such a manner that the present unit is related to the next unit. For this reason, you are advised to
read this module. After each unit, there are exercises to be given. Submission of task given will be submitted by
the agreed deadline.
Page - 3 - of 13
Operating System Scheduling Algorithms
The Process Scheduler schedule different processes to be assigned to the CPU based on particular scheduling
algorithm. There are six popular process scheduling algorithms which we are going to discuss in the following
section:
∙ First-Come, First-Served (FCFS) Scheduling
∙ Shortest-Job-Next (SJN) Scheduling
∙ Priority Scheduling
∙ Round Robin(RR) Scheduling
These algorithms are either nonpreemptive or preemptive. Non-preemptive algorithms are designed so that
once a process enters the running state, it cannot be preempted until it completes its allotted time where as the
preemptive scheduling is based on priority where a scheduler may preempt a low priority running process
anytime when a high priority process enters into a ready state.
First Come First Serve (FCFS)
∙ Jobs are executed on first come, first serve basis.
∙ It is a nonpreemptive scheduling algorithm.
∙ Easy to understand and implement.
∙ Its implementation is based on FIFO
queue.
Process Arrival Execute
Time Time
P0 0
P1 1
P2 2
P3 3
∙ Poor in performance as average wait time is high.
P0 0-0=0
Step by Step Example:
P1 5-1=4
How FCFS Works? Calculating Average Waiting Time
P2 8-2=6
Average Wait Time: (0+4+6+13)/4=5.75
Here is an example of five processes arriving at different times. Each process has a different burst time.
Page - 4 - of 13
(Step 0) The process begins with P4 which has arrival time 0 Process
P1 6 2
P2 3 5
P3 8 1
P4 3 0
P5 4 4
P1 6 2
P2 3 5
P3 8 1
P4 3 0
P5 4 4
Page - 5 - of 13
Process Burst time Arrival time
P1 6 2
P2 3 5
P3 8 1
P4 3 0
P5 4 4
P1 6 2
P2 3 5
P3 8 1
P4 3 0
P5 4 4
Page - 6 - of 13
Process Burst time Arrival time
P1 6 2
P2 3 5
P3 8 1
P4 3 0
P5 4 4
Step 7) At time=11, P1 starts execution. It has a burst time of 6. It completes execution at time interval
17
time=21
Step 9) At time=21, P2 starts execution. It has a burst time of 2. It completes execution at time interval
23
Step 10) Let's calculate the average waiting time for above example.
Page - 7 - of 13
Waiting time = Start time - Arrival time P4 = 0-0 = 0 P5= 17-4 = 13
P2= 21-5= 16
P3 = 3-1 = 2
PI = 11-2 = 9
Average Waiting Time = 40/5= 8
In the following example, we have 4 processes with process ID P0, P1, P2, and P3. The arrival time of P0 is 0, P1
is 1, P2 is 2, and P3 is 3. The arrival time and burst time of the processes are given in the following table.
The waiting time and Turnaround time are calculated with the help of the following
P0 0 6 6 6 0
P1 1 8 14 13 5
P2 2 10 24 22 12
P3 3 12 36 33 21
P0 0 5 3
P1 1 3 0
P2 2 8 16
P3 3 6 8
P0 3-0=3
P1 0-0=0
P2 16-2=14
P3 8-3=5
Consider the below processes available in the ready queue for execution, with arrival time as 0 for all and
Shortest Job First (SJF) is an algorithm in which the process having the smallest execution time is chosen for the
next execution. This scheduling method can be preemptive or non-preemptive. It significantly reduces the
average waiting time for other processes awaiting execution. The full form of SJF is Shortest Job First.
Page - 2 - of 13
Characteristics of SJF Scheduling
Non-Preemptive SJF
In non-preemptive scheduling, once the CPU cycle is allocated to process, the process holds it till it reaches a
waiting state or terminated.
Consider the following five processes each having its own unique burst time and arrival time.
Process Queue Burst time Arrival time P1 6 2 P2 Step 0) At time=0, P4 arrives and starts execution.
2 5 P3 8 1 P4 3 0 P5 4 4
execution.
Page - 3 - of 13
Step 6) At time = 9, process P1 will finish its execution. The burst time of P3, P5, and P2 is compared. Process P2
is executed because its burst time is the lowest.
Step 8) At time = 11, process P2 will finish its execution. The burst time of P3 and P5 is compared. Process P5 is
Step 11) Let's calculate the average waiting time for above example.
Wait time
P4= 0-0=0
P1= 3-2=1
P2= 9-5=4
P5= 11-4=7
P3= 15-1=14
Average Waiting Time= 0+1+4+7+14/5 = 26/5 = 5.2
Page - 4 - of 13
Lab Activity
Research Activity: The input and output process of Shortest Job First (SJF) Scheduling Algorithm is given
below. Explain how the FCFS scheduling algorithm solved the problem. Is the solution correct? *Consider the
following set of processes, with the length of the CPU burst given in milliseconds:
0 3 9 16 24
Process ID Burst Time P4 P1 P3 P2
P1 6
P4 3
By comparison, if we were using the FCFS scheduling scheme, the average waiting time would be
10.25 millisecond.
Problem Solving:
Use the First Come First Served Scheduling Algorithm to solve the average waiting time below.
Customer Arrival Time Burst Time
J1 0 2
J2 2 5
J3 5 2
J4 6 1
J5 8 5
J6 12 2
Page - 5 - of 13
Exercises
Test I: The input and output process of First Come First Serve Scheduling Algorithm is given below.
a.) Explain how the FCFS scheduling algorithm solved the problem. Is the solution correct? And what is your
insight about the topic?
*Consider the set of 5 processes whose arrival time and burst time are given below:
Process ID Arrival Time Burst Time
P1 4 5
P2 6 4
P3 0 3
P4 6 2
P5 5 4
Calculate the average waiting time and average turnaround time, if FCFS scheduling algorithm is
followed.
P3 P1 P
0 3 49 13 17 19
P1 9 9-4=5 5-5=0
P2 17 17-6=11 11-4=7
P3 3 3-0=3 3-3=0
P4 19 19-6=13 13-2=11
P5 13 13-5=8 8-4=4
Now,
Average Turn Around Time = (5 + 11 + 3 + 13 + 8) / 5
= 40/5
= 8 units
b.) what is preemptive and non-preemptive and their difference. c.) Give
Page - 6 - of 13