CH4 and CH5-CPU Scheduling V1
CH4 and CH5-CPU Scheduling V1
CPU SCHEDULING
CONTEN
TS :
CPU Scheduling
Types of Schedulers
Scheduling criteria
Scheduling algorithms
CHARACTERISTICS OF GOOD PROCESS
SCHEDULER-
The characteristics of a good process scheduler are as follows −
Long Term
Short Term
Medium Term
4
TYPES OF SCHEDULING
Long Term job scheduler :
It brings the new process to the ‘Ready State’. It controls Degree of Multi-
programming, i.e., number of process present in ready state at any point of
time.
It is important that the long-term scheduler make a careful selection of both I/O
and CPU-bound processes.
I/O bound tasks are which use much of their time in input and output
operations while CPU bound processes are which spend their time on CPU. The
job scheduler increases efficiency by maintaining a balance between the two.
TYPES OF SCHEDULING
Short term CPU scheduler :
MAXIMIZE:
CPU utilization - It makes sure that the CPU is operating at its peak and is busy
or CPU busy if possible and to maximize its usage. In theory, the range of CPU
utilization is in the range of 0 to 100 but in real-time, it is actually 50 to 90% which relies on the
system’s load.
Throughput - It is the number of processes that complete their execution per
unit of time.
SCHEDULING CRITERIA
MINIMIZE:
Response time- Time retired for generating the first request after submission.
READY
RUN
WAIT
13
COMBINATION OF SCHEDULING & PROCESSS STATES
14
Differences between long term, medium term and short
term scheduler are as follows −
Long term scheduler Medium term scheduler Short term scheduler
Terminated or exit: – When the process finishes its execution or it its terminated by operating system, it
is moved to terminated state.
Dispatcher: – Dispatcher is one of the important entity in CPU scheduling. A dispatcher is placed in
between the ready queue and Short-term scheduler. When the short-term scheduler makes decision that
which process from among the several processes waiting in the ready queue will be allocated CPU next for its
execution, it is the dispatcher that assigns CPU to that selected process.
Context switching:- A dispatcher switch execution from one process to another is called context
switching.
Dispatcher Latency: – dispatcher latency is the amount of time taken by the system to stop one process
16
Shortest-Job-First (SJF)
Scheduling
Completion Time: Time at which process completes its execution.
Turn Around Time: Time Difference between completion time and arrival time.
Turn Around Time = Completion Time – Arrival Time
Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time
Burst Time
Burst time, also referred to as “execution time”. It is the amount of CPU time
the process requires to complete its execution. It is the amount of processing
time required by a process to execute a specific task or unit of a job. Factors
such as the task’s complexity, code efficiency, and the system’s resources
determine the process’s burst time.
https://www.geeksforgeeks.org/program-for-shortest-job-first-or-sjf-cpu-scheduling-set-1-non-preemptive/
TYPES OF SCHEDULING ALGORITHM
A Process Scheduler schedules different processes to be assigned to the
CPU based on particular scheduling algorithms. There are six popular
process scheduling algorithms .
P2 , P3 , P1
Answer: ?
Prepare Gantt chart for the scheduling
P2 , P3 , P1
P2 P3 P1
0 3 6 30
Burst Time
Burst time, also referred to as “execution time”. It is the amount of CPU time
the process requires to complete its execution. It is the amount of processing
time required by a process to execute a specific task or unit of a job. Factors
such as the task’s complexity, code efficiency, and the system’s resources
determine the process’s burst time.
https://www.geeksforgeeks.org/program-for-shortest-job-first-or-sjf-cpu-scheduling-set-1-non-preemptive/
SHORTEST-JOB-FIRST (SJF) SCHEDULING
The shortest job first (SJF) or shortest job next, is a scheduling policy that selects the waiting process
with the smallest execution time to execute next. SJN, also known as Shortest Job Next (SJN), can be
preemptive or non-preemptive.
Shortest Job first has the advantage of having a minimum average waiting time among all scheduling
algorithms.
It is a Greedy Algorithm.
It may cause starvation if shorter processes keep coming. This problem can be solved using the
concept of ageing.
It is practically infeasible as Operating System may not know burst times and therefore may not
sort them. While it is not possible to predict execution time, several methods can be used to
estimate the execution time for a job, such as a weighted average of previous execution times.
SJF can be used in specialized environments where accurate estimates of running time are
available.
SHORTEST-JOB-FIRST (SJF) SCHEDULING
Advantages of SJF:
SJF is better than the First come first serve(FCFS) algorithm as it reduces the average waiting
time.
SJF is generally used for long term scheduling
It is suitable for the jobs running in batches, where run times are already known.
SJF is probably optimal in terms of average turnaround time.
Disadvantages of SJF:
Answer: ?
Prepare Gantt chart for the scheduling
Calculate waiting time for P1 P2 P3
Calculate average waiting time
Calculate turnaround time TAT (Turnaround Time) = Completion Time (CT) – Arrival Time (AT)
Calculate response time WT (Waiting Time) = Turnaround Time (TAT) – Burst Time (BT)
Shortest-Remaining-Time-First(SRTF)
https://mycareerwise.com/content/srtf-process-and-
examples/content/exam/gate/computer-science
29
PRIORITY SCHEDULING
Answer: ?
Prepare Gantt chart for the scheduling
• Preemptive or Non-preemptive?
ROUND ROBIN (RR)
The Round-robin scheduling algorithm is a kind
of preemptive First come, First Serve CPU
Scheduling algorithm where each process in the
ready state gets the CPU for a fixed time in a
cyclic way (turn by turn). It is the oldest
scheduling algorithm, which is mainly used
for multitasking.
Disadvantages
The Disadvantages of Round Robin CPU Scheduling are:
Low Operating System slicing times will result in decreased CPU output.
Round Robin CPU Scheduling approach takes longer to swap contexts.
Time quantum has a significant impact on its performance.
The procedures cannot have priorities established.
35
EXAMPLE OF RR WITH TIME
QUANTUM = 4
Process Burst Time
P1 24
P2 3
P3 3
• Answer: ?
• Prepare Gantt chart for the scheduling
• Calculate waiting time for P1 P2 P3
• Calculate average waiting time
• Calculate turnaround time
• Calculate response time
EXAMPLE OF RR WITH TIME
QUANTUM =
ProcessBurst Time
4
P1 24
P2 3
P3 3
The Gantt chart is:
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30
Waiting Time:
P1 =10-(1*4)=6 ms
P2 =4 ms
P3 =7 ms
• Average Waiting: =(6+4+7)/3 =5.66 ms
• Typically, higher average turnaround than SJF, but better response
ROUND ROBIN (RR)
• Solution:
You can argue about a multi-core CPU, but what if you had a single CPU
available?
Multilevel queue scheduling is one such CPU scheduling algorithm where the tasks
to be performed by the CPU are divided into different groups based on various
properties.
MULTILEVEL QUEUE SCHEDULING'S WORKING
example where the processes are divided into three different queues given below.
40
MULTILEVEL QUEUE SCHEDULING'S WORKING
When a new process comes, that process is added to one of the above-given
three process queues based on the classification specified for those process
queues.
Interactive processes: Let us assume that an interactive process like online
gaming wants to utilize the CPU. Then this process will be placed in the
Interactive processes queue.
System Processes: If any process owned by the operating system itself comes,
it is placed in the System Processes queue, and similarly for other processes.
Now we have the question of which process will go first in the CPU if all the
process queues have some processes. This dilemma can be solved in different
ways. We have discussed two different ways to solve it.
41
Multilevel Queue Scheduling
FIXED PRIORITY PREEMPTIVE SCHEDULING
METHOD
Each queue is assigned an absolute priority over other queues in this method. For
example, let us consider the following priority order:
According to this priority order, all the processes in the System Processes
queue are initially run, and we don't move to the next process queue until the
current process queue is empty. When all the system queue processes are
executed, we move to the following priority process queue. And similarly, for the
next lower-priority queues.
Suppose we are running the processes from the Interactive process queue, and a
new process arrives in the System processes queue which is of higher priority?
Then we will run the system process first, and then we will move to the
interactive process, and that too only when the system process queue is empty.43
TIME SLICING METHOD
In this method, processes from each queue are run for a fixed amount of time, and then we move on to the next queue.
When we arrive at the last queue, we run it for a specific amount of time, and then we move back to the first queue.
For example, queue1 runs for 50% of CPU time, queue two runs for 30% of CPU time, and queue three runs
for 20% of CPU time. In this way, the total CPU time is divided among each queue to run their processes.
We have solved our problem of processes of which queue is to be run first. Now, we come to the fate of individual
queues. In each queue, we have multiple processes, so how to decide which process should be run first and for how
much time. And do we need to run the processes in all the queues in the same manner as we did in queue one, or can
we implement different ways to run the processes in different queues?
The answer to this question is that we can have different implementations for each queue. And there are many
algorithms using which we can decide the process to be run first and for how long.
For example:
The system process queue can use FCFS(First Come, First Serve) scheduling.
The interactive process queue can use SJF(Shortest Job First) scheduling.
The batch process queue can use RR(Round Robin) scheduling.
44
PROPERTIES OF MULTILEVEL QUEUE SCHEDULING
Multilevel Queue Scheduling distributes the processes into multiple queues based on the properties of
the processes.
Each queue has its own priority level and scheduling algorithm to manage the processes inside that
queue.
Queues can be arranged in a hierarchical structure.
High-priority queues might use Round Robin scheduling.
Low-priority queues might use First Come, First Serve scheduling.
Processes can move between queues based on their behavior or performance.
This algorithm prioritizes different types of processes and ensures fair resource allocation.
45
CPU AND I/O BURST CYCLE
• To Maximize CPU utilization by distinguishing
time required by process for CPU execution and
time required by process for I/O or other
operations are named as follows:
• CPU burst
• I/O burst
T2: William Stallings, Operating Systems: Internals and DesignPrinciples,7th edition Pearson Education
REFERENCE BOOKS
R2: Godbole , Kahate, "Operating System: A Concept Based Approach", Tata Mc-Graw-Hill.
• https://www.geeksforgeeks.org/operating-systems/
• https://www.geeksforgeeks.org/operating-systems/
47
THANK YOU