0% found this document useful (0 votes)
27 views59 pages

Module 3

Computer Networks chapter 3

Uploaded by

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

Module 3

Computer Networks chapter 3

Uploaded by

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

BCSE303L - Operating Systems

Module:3 Scheduling

Dr. P. Anandan
Mail: [email protected]
Mobile: 8056445321
Module:3 Scheduling

Processes Scheduling - CPU Scheduling: Pre-emptive,


non-pre-emptive – Multiprocessor scheduling –
Deadlocks - Resource allocation and management -
Deadlock handling mechanisms: prevention, avoidance,
detection, recovery.

Dr.P.Anandan
Processes Scheduling & CPU Scheduling

• There are multiple processes in a computer


system.
• A program in execution is known to be a process.
• The objective of multiprogramming is to have
some process running at all times, to maximize
the CPU utilization.
• The objective of time sharing is to switch the
CPU among processes so frequently that users can
interact with each program while it is running.
• Process Scheduling and CPU Scheduling are
associated with process execution.
Dr.P.Anandan
CPU
Scheduling

Process / Job
Scheduling

Process Life Cycle

Dr.P.Anandan
Job Scheduling vs CPU Scheduling
The CPU scheduling is the mechanism to
The job scheduling is the mechanism to
select which process has to be executed
select which process has to be brought
next and allocates the CPU to that
into the ready queue.
process.
Synonyms
The job scheduling is also known as the The CPU scheduling is also known as
long-term scheduling. short-term scheduling.
Processed By

The job scheduling is done by the long- The CPU scheduling is done by the short-
term scheduler or the job scheduler. term scheduler or the CPU scheduler.

Process State Transition


The process transfers from new state to The process transfers from ready state to
ready state in job scheduling. running state in CPU scheduling.
Multiprogramming
More control over multiprogramming in Less control over multiprogramming in
Job Scheduling. CPU Scheduling.

Dr.P.Anandan
Scheduler
Schedulers are special system software that handles scheduling in various ways.
Their main task is to select the jobs to submit into the system and decide which
process to run. There are three types of schedulers in an operating system.

Dr.P.Anandan
Scheduling Queues
• Job Queue: As processes enter the system,
they are put into a job queue, which consists of
all processes in the system.
• Ready Queue: The processes that are residing
in main memory and are ready and waiting to
execute are kept on a list called the ready
queue.

Dr.P.Anandan
Different CPU times
• Arrival Time (AT):
Time at which the process arrives in Ready queue
• Completion time (CT):
Time at which the process complete its execution
• Burst Time (BT):
Process/CPU execution time
• Turn Around Time (TAT) : Difference between
submission of process and completion of process
(TAT) = CT – AT

Dr.P.Anandan
• Waiting time (WT):Time spent by process in
Ready Queue.
Waiting Time (WT) = TAT - BT

• Response Time (RT): Time spent by process in


Ready queue and gets CPU for first time.

• Throughput: Number of processes being executed


and completed / time. Throughput depends upon
the duration of each processes.

Dr.P.Anandan
Optimization Criteria
•Max CPU utilization
•Max throughput
•Min turnaround time
•Min waiting time
•Min response time
CPU scheduling decisions take place under one
of four conditions:
1. When a process switches from the running state to the
waiting state, such as for an I/O request or invocation
(Invoke) of the wait( ) system call.
2. When a process switches from the running state to the
ready state, for example in response to an interrupt.
3. When a process switches from the waiting state to the ready
state, say at completion of I/O or a return from wait( ).
4. When a process terminates.

1,4 – Non preemptive


2,3 – Preemptive

Dr.P.Anandan
Pre-emptive scheduling Non-Preemptive
scheduling
• The currently running process • The running process
may be interrupted and moved to can only lose the
the ready state by OS (forcefully). processor voluntarily
by terminating or by
requesting an I/O.
Or
• Once CPU given to a
process it cannot be
preempted until the
process completes its
CPU burst.

Dr.P.Anandan
PREEMPTIVE NON-PREEMPTIVE
Parameter
SCHEDULING SCHEDULING

In preemptive, While in Non-preemptive, Once


resources (CPU resources (CPU Cycles) are allotted
Basic Cycle) are allotted to to a process, it is held until the burst
a process for a time is completed or the process
limited time. transitions to the waiting state.

The process can be The process cannot be interrupted


Interrupt interrupted at any until it has been completed or the
time. timer has expired.

A low priority
process may starve if
If a process with a long burst time
a high priority
Starvation consumes CPU, subsequent processes
process often
with shorter burst times may suffer.
appears in the ready
queue.
Dr.P.Anandan
PREEMPTIVE NON-PREEMPTIVE
Parameter
SCHEDULING SCHEDULING
It contains overheads
There are no overheads in
Overhead associated with process
Non-preemptive scheduling.
scheduling.

There is a cost associated There is no cost associated


Cost with preemptive with non-preemptive
scheduling. scheduling.

CPU CPU consumption is high CPU consumption is low in


Utilization in preemptive scheduling. Non-preemptive scheduling.

Some of the preemptive Some non-preemptive


scheduling is Shortest scheduling is Shortest Job
Examples
Remaining Time First and First and First Come First
Round Robin. Serve.

Dr.P.Anandan
Pre-emptive Non-Preemptive
scheduling scheduling

1. Shortest Remaining Time 1. First Come First Serve


First (SRTF) (FCFS)
2. Round Robin (RR) 2. Shortest Job First (SJF)
3. Priority (preemptive version) 3. Priority (non preemptive
version)

Dr.P.Anandan
Non-Preemptive scheduling
1. First Come First Serve (FCFS)
•First Come, First Served (FCFS) also known as First In, First
Out(FIFO) is the CPU scheduling algorithm in which the CPU is
allocated to the processes in the order they are queued in the
ready queue.
•FCFS follows non-preemptive scheduling which mean once the
CPU is allocated to a process it does not leave the CPU until the
process will not get terminated or may get halted due to some
I/O interrupt.
•Buying a movie ticket from the ticket counter is a perfect real-
life example of a first come first serve (FCFS) algorithm. The
person who comes first and stands in the queue gets to buy the
ticket first. Similarly in the fcfs scheduling algorithm, the
process which arrives first gets executed first.

Dr.P.Anandan
Problem 1: Consider the set of 5 processes whose arrival time
and burst time are given below. Calculate the average TAT and
average WT if First Come First Serve (FCFS) scheduling
algorithm is followed
Process Burst Arrival
Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Ready Queue

Process Burst Arrival


Name Time Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Process Name Burst Time Arrival Time

P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Job AT BT CT TAT =CT-AT WT=TAT-BT


P4 0 3 3 3-0=3 3-3=0
P3 1 8 11 11-1=10 10-8=2
P1 2 6 17 17-2=15 15-6=9
P5 4 4 21 21-4=17 17-4=13
P2 5 2 23 23-5=18 18-2=16
Average 63/5=12.6 40/5=8
Advantage of FCFS Disadvantage of FCFS
• It is simple and • Convoy Effect:
easy to If processes with higher
burst time arrived before
understand. the processes with smaller
burst time, then, smaller
processes have to wait for
a long time for longer
processes to release the
CPU. This effect results in
lower CPU and device
utilization.

Dr.P.Anandan
12/01/2023
Shortest Job First (SJF)(NPE)

Dr.P.Anandan
2. Shortest Job First (SJF)
• 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

Dr.P.Anandan
• This algorithm method is helpful for batch-
type processing, where waiting for jobs to
complete is not critical.
• It can improve process throughput by making
sure that shorter jobs are executed first, hence
possibly have a short turnaround time.
• It improves job output by offering shorter jobs,
which should be executed first, which mostly
have a shorter turnaround time.

Dr.P.Anandan
Problem2. (SJF – Non Preemptive)
Consider the set of 5 processes whose arrival time and burst time
are given below. Calculate the average TAT and average WT if
SJF Non Preemptive scheduling algorithm is followed

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Ready Queue

Dr.P.Anandan
Dr.P.Anandan
Process Name Burst Time Arrival Time

P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Job AT BT CT TAT =CT-AT WT=TAT-BT


P4 0 3 3 3-0=3 3-3=0
P1 2 6 9 9-2=7 7-6=1
P2 5 2 11 11-5=6 6-2=4
P5 4 4 15 15-4=11 11-4=7
P3 1 8 23 23-1=22 22-8=14
Average 49/5=9.8 26/5=5.2
19/01/2023

Dr.P.Anandan
3. Shortest Remaining Time First (SRTF)
(SJF – Preemptive)
• Preemptive version of SJF is known as Shortest
Remaining Time First (SRTF).
• In the Shortest Remaining Time First (SRTF)
scheduling algorithm, the process with the smallest
amount of time remaining until completion is
selected to execute.

Dr.P.Anandan
Problem3. (SJF – Preemptive)
Consider the set of 5 processes whose arrival time and burst time
are given below. Calculate the average TAT and average WT if
SJF Preemptive scheduling algorithm is followed

Dr.P.Anandan
Process Burst Arriva
Name Time l Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Process Burst Arriva
Name Time l Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Dr.P.Anandan
Dr.P.Anandan
Dr.P.Anandan
Dr.P.Anandan
Process Burst Arriva
Name Time l Time
P1 6 2
P2 2 5
P3 8 1
P4 3 0
P5 4 4

Job AT BT CT TAT =CT-AT WT=TAT-BT

P1 2 6 15 15-2=13 13-6=7
P2 5 2 7 7-5=2 2-2=0
P3 1 8 23 23-1=22 22-8=14
P4 0 3 3 3-0=3 3-3=0
P5 4 4 10 10-4=6 6-4=2
Average 46/5=9.2 23/5=4.6

Dr.P.Anandan
4. Priority Scheduling (Non Preemptive)
(#lower value- Higher Priority)
• Before letting in the new process BT is
checked in SJF/SJN, here Priority is checked.
• In SJF/SJN after D execution, A got executed
next because BT of A (6) < BT of C (8).
• Now set the priority of C to #1 and A to #5,
remaining priority assign randomly.
Example: Priority Scheduling (Non Preemptive)
5. Priority Scheduling (Preemptive)
6. Round Robin Scheduling (Preemptive)

Ready
D C A D E C B A E C A C
Queue
PS – Round Robin – AT Zero
Dr.P.Anandan

You might also like