Lecture 3 - Process Scheduling
Lecture 3 - Process Scheduling
System
2. Waiting Time
• The total time spent in the ready queue by a process.
• Scheduling algorithms are designed to have a minimum
waiting time.
3. Response Time
• The time period between the submission of a process
and the first response given by the process to the user.
• Scheduling algorithms are designed to have a response
time that is within the acceptable range.
Scheduling Algorithms
Design Requirements
4. Throughput
• The number of processes completed in a unit time.
• Scheduling algorithm are designed to maximize the
throughput of the system.
5. CPU Utilization
• The percentage of time that the CPU is busy in executing
the processes.
• The fundamental requirement is that the processor
should be busy most of the time.
Scheduling Algorithms
Design Requirements
6. Fairness
• All processes in the system should get a chance to the
CPU, lower priority processes should not be ignored
indefinitely.
• A scheduling algorithm should not allow any process to
starve.
7. Balance
• At a particular instant of time, all resources should be
used in balance.
• A scheduling algorithm should select a proper mix of
CPU-bound and I/O-bound processes
Scheduling Algorithms
First Come First Served (FCFS)
• The process that comes first to the ready queue will be
served first.
• The arriving process is added onto the tail of the queue
and the process at the head of the queue is dispatched
to the processor for execution.
• In this way, a ready queue is implemented as a linked list
wherein the order of arrival of the processes is
maintained with the simple logic of first in, first out
(FIFO).
• This scheduling policy is non pre-emptive, a process
which has arrived first will be executed first to its
completion
• A running process is moved back to the tail of the ready
queue if interrupted.
Scheduling Algorithms
First Come First Served (FCFS)
Example 3.1
Scheduling Algorithms
First Come First Served (FCFS)
Example 3.1 solution
Disadvantages
• With no pre-emption, it cant be used in multi-user or
real-time systems
• Shorter processes surfer longer waiting times due to
long processes
Scheduling Algorithms
Priority Scheduling
• The order of arrival of processes does not matter.
• This algorithm is pre-emptive, when a process with
higher priority has arrived late it will be executed first
according to its priority.
• Priorities are defined as a number associated with a
process.
• In most cases, lower numbers are considered as high
priorities but some systems implement a different
number scheme
• Disadvantages: Low priority processes may be starved
Scheduling Algorithms
Priority Scheduling
Example 3.2
Scheduling Algorithms
Priority Scheduling
Example 3.2 solution
SRN
Process Arrival Time Execution Execution Waiting Turn around Norm. Turn
Time (x) Start Time Time Time (t) Around Time (x/t)
P1 0 9 0,13 12 21 2.34
P2 1 5 1,5 3 8 1.6
P3 2 3 2 0 3 1
P4 3 4 9 6 10 2.5
Av = 5.25 Av = 10.5 Av = 1.86
Scheduling Algorithms
Round Robin Scheduling (RR)
• The scheduling methods discussed so far do not
guarantee fair response times to all processes hence can
cause starvation to some processes
• With FCFS, tasks are processed according to the order of
their arrivals. A process arriving late may not get
response for a long time especially if earlier processes
are longer.
• With Priority scheduling, low priority processes can wait
for longer times before getting access to a processor
• With SPN/SRN, long processes may need to wait for a
long period before getting access to a processor
Scheduling Algorithms
Round Robin Scheduling (RR)
• With round robin algorithm, each arriving process gets
the same amount of time for execution.
• If each process gets the same processor time, neither
the short nor long process can suffer from starvation.
• To implement the round robin algorithm, the following
design issues are considered
i) The ready queue is maintained as a FIFO queue.
ii) A fixed time period is allotted to every arriving
process in the queue. This time period is known as time
slice or time quantum.
Scheduling Algorithms
Round Robin Scheduling (RR)
iii) The first arriving process is selected and dispatched
to the processor. But if it is not able to complete its
execution within its time slice, then an interrupt is
generated.
iv) As soon as the timer interrupt arrives, the running
process is stopped temporarily, and placed back in the
ready queue at the end of the queue.
v) The scheduler selects another process from the
queue and dispatches it to the processor. It is executed
until the allotted time slice expires.
vi) When a process finishes before the time slice
expires, the timer will stop and send the interrupt
signal, so that the next process can be scheduled.
Scheduling Algorithms
Round Robin Scheduling (RR)
Example 3.5
Scheduling Algorithms
Round Robin Scheduling (RR)
Example 3.5 solution
Process Arrival Time Execution Execution Start Waiting Turn around Normalized
Time (x) Time Time Time (t) Turn around
Time (x/t)
P1 0 3 0,1,8 6 9 3
P2 2 3 2,9,12 8 11 3.67
P3 3 2 3,4 0 2 1
P4 5 4 5,6,10,13 5 9 2.25
P5 7 2 7,11 3 5 2.5
Average Average Average
waiting time turnaround normalized
= 4.4 time = 7.2 turnaround
time = 2.484
Scheduling Algorithms
Highest Response Ratio Next Scheduling (HRRN)
Example 3.6 Solution
HRRN scenario
Response ratio calculation
Scheduling Algorithms
Highest Response Ratio Next Scheduling (HRRN)
Example 3.6 Solution
HRRN scenario
Process Arrival Time Execution Execution Start Waiting Turn around Normalized
Time (x) Time Time Time (t) Turn around
Time (x/t)
P1 0 3 0,1,4 2 5 1.67
P2 2 3 2,6,10 6 9 3
P3 3 2 3,8 4 6 3
P4 5 4 5,9,12,13 5 9 2.25
P5 7 2 7,11 3 5 2.5
Average Average Average
waiting time turnaround normalized
=4 time = 6.8 turnaround
time = 2.484
Scheduling Algorithms
Multi level Queue Scheduling
• The basic idea behind multiple queues is that all
processes are not of the same nature.
• Processes can be categorized into:
i. Interactive processes
ii. Non-interactive processes
iii. CPU-bound processes
iv. I/O-bound processes
v. Foreground processes
vi. Background processes