0% found this document useful (0 votes)
46 views17 pages

CPU Sceduling

Uploaded by

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

CPU Sceduling

Uploaded by

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

Operating System

Concepts Presentation
Topic : CPU Scheduling and
Scheduling Algorithms
Outlines or Topics to be covered :

1 . Introduce CPU scheduling , which is the basis for multiprogrammed


OS .
2 . Describe various CPU scheduling algorithms .
3 . Importance of CPU Scheduling .
CPU Scheduling :
CPU Schedling is the basis of multi-
programmed operating systems .
By switching the CPU among processes , the operating systems can make the
computer more productive .

Difference of Single Processor & Multi-processor System :

⮚ Single Processor System


• In a Single processor System , only one process can run at a time .
• Any other process have to wait until the previous process is complete and the cpu can be
rescheduled .

⮚ Multi-processor System :
• The objective of the multi-programmed system is to have some process running at all
time , to maximize the cpu utilization .

▪ A process is executed until it must wait , typically for the completion of some I/O
requests .
But in case of multi-programming we can utilize this waiting time
productively .

Way to increase the productivity :


• Instead of only one process , several processes are kept in the memory at
one time .

• When the one process has to wait , the OS takes the cpu away from that
process and gives the CPU to another process & this process continues …..
Types of CPU Scheduling :

Scheduling

Pre-emptive Non Pre-emptive

Pre-emptive : In Preemptive Scheduling, the tasks are mostly assigned with


their priorities. Sometimes it is important to run a task with a higher priority
before another lower priority task, even if the lower priority task is still
running. The lower priority task holds for some time and resumes when the
higher priority task finishes its execution.

Non Pre-emptive : In this type of scheduling method, the CPU has been
allocated to a specific process. The process that keeps the CPU busy will
release the CPU either by switching context or terminating.
CPU Scheduling
Algorithms :

✔ First come first serve


✔ Shortest job first
scheduling
✔ Shortest remaining time
scheduling
✔ Priority Scheduling
✔ Round Robin Scheduling
✔ Multi-level queue
scheduling
First Come First Serve (FCFS) :
• By far the simplest scheduling algorithm .
• The process that requests the cpu first will be provided the CPU
first .
• The FCFS policy is easily managed with the FIFO queue .

First In First Out

Tail 4 3 2 1 Head
CPU

• When the CPU is free the head will be move to the CPU for
processing
• After completion the process will be removed from the queue .
• Any new process will be added to the tail of the queue .
Finding the Average waiting time as per FCFS
policy : Process Burst
Time(ms)
If the processes arrive in the order P1 , P2 , P3 and served in FCFS
order P1 24
The result will be shown as per the Grantt Chart :- P2 3
P3 3
P1 P2 P3

0 24 27 30

Average waiting time = (0+24+27) / 3 = 17 ms


Waiting time for P1 = 0 ms
Waiting time for P2 = 24 ms
Waiting time for P3 = 27 ms
Now lets take the same table :
Process
If the processes arrive in the order P2 , P3 , P1 and served in FCFS Burst
Time(ms)
order
The result will be shown as per the Grantt Chart :- P1 24
P2 3
P3 3
P2 P3 P1
0 3 6 30

Waiting time for P1 = 6 ms Average waiting time = (6+0+3) / 3 = 3 ms


Waiting time for P2 = 0 ms
Waiting time for P3 = 3 ms

Thus the average waiting time under an FCFS policy is generally


not minimal and may vary substantially if the process’s CPU burst
FCFS scheduling algorithm is Non pre-emptive
times vary greatly .
Shortest job first Scheduling (SJF) :
• SJF is a full form of (Shortest job first) is a scheduling algorithm in which the process with
the shortest execution time should be selected for execution next. The process that
requests the cpu first will be provided the CPU first .

• When the CPU is free , it is assigned to the process that has the
smallest next CPU burst

• If the next CPU burst of two processes are same then the FCFS
scheduling is used to break the tie .

SJF scheduling algorithm can be either pre-emptive or Non pre-emptive


Example of SJF Scheduling (Non-Pre-emptive) :
Process Burst
Consider All the processes arrive at same
Time(ms)
time .
P1 6
Gantt Chart : P2 8
P3 7
P4 P1 P3 P2 P4 3
0 3 9 16 24

Waiting time for P1 : 3 ms


Waiting time for P2 : 16 ms Average waiting time = (3+16+9+0) / 4 =
Waiting time for P3 : 9 ms 7 ms
Waiting time for P4 : 0 ms In comparision if we use FCFS algorithm on this same
problem the average waiting time will be 10.25 ms
Example of SJF Scheduling (Pre-emptive) :
Process Burst Arrival
Time(ms) Time(ms
)

Gantt Chart : P1 8(8-1=7) 0


P2 4 1

P1 P2 P4 P1 P3 P3 9 2

0 1 5 10 17 26 P4 5 3

Waiting Time = Total waiting time – No. of ms process executed – Arrival


time

Waiting time for P1 = (10-1-0) = 9 ms Average waiting time = (9+0+15+2) / 4 = 6.5 ms


Waiting time for P2 = (1-0-1) = 0 ms
Waiting time for P3 = (17-0-2) = 15 ms
Waiting time for P4 = (5-0-3) = 2 ms

*** Pre-emptive SJF Scheduling is sometimes called Shortest-Remaining-Time-First-Scheduling ***


Priority Scheduling Algorithm :
• A priority is associated with each process , and the CPU is allocated to
the process with the highest priority .

• Equal priority processes are scheduled in FCFS order .

• An SJF is a priority algorithm where the priority is the inverse of of the


next CPU burst .
• The larger the CPU burst , the lower the priority and vice versa .

Priority scheduling algorithm can be either pre-emptive or Non pre-emptive

• A pre-emptive priority scheduling will pre-empt the cpu if the priority of


newly arrived process is higher than the prority of the currently running
process.

• A Non-preemptive priority scheduling algorithm will simply put the new


process at the head of the ready queue .
Consider the following set of processes , assumed to have arrived at time 0 , Burst
Process Priority
Id in msTime(ms)
in the order P1 , P2 , P3 , P4 , P5With the length of the CPU burst given
P1 10 3
Using the priority scheduling , we can schedule the process as per theP2 1 1
Following Gantt Chart :
P3 2 4
P4 1 5
P2 P5 P1 P3 P4
P5 5 2
0 1 6 16 18 19

Waiting time for P1 : 6 ms


Waiting time for P2 : 0 ms
Waiting time for P3 : 16 ms Average waiting time = (6+0+16+18+1) / 5
Waiting time for P4 : 18 ms = 41/5 = 8.2
Waiting time for P5 : 1 ms
Problems of Priority Scheduling :
• Major problem with priority scheduling is indefinite blocking or starvation
• A priority scheduling can leave some low priority process waiting indefinitely .

Solution of this problem ;


• A solution to the problem of indefinite blockage of low-priority process is aging
.
• Aging is a technique of gradually increasing the priority of processes that wait
in the system for long time .

• For example ,
If priorities range from 127 (low) to 0 (high) , we could increase the
priority of a waiting process
By 1 in every 5 mins .

Eventually even a process with initial priority of 127 would have the highest
priority after a point of time and the process will be executed .
The Purpose of a Scheduling
algorithm :

Here are the reasons for using a scheduling


algorithm :

•The CPU uses scheduling to improve its efficiency.


•The maximum utilization of CPU can be obtained
with multi-programming.
•The processes which are to be executed are in
ready queue.
Thank
You

You might also like