0% found this document useful (0 votes)
5 views47 pages

Final Term PPtT 1_ CPU Scheduling

The document provides an overview of CPU scheduling, detailing its fundamental concepts, types of schedulers, and various scheduling algorithms such as FCFS, SJF, and Round Robin. It emphasizes the importance of optimizing CPU utilization and ensuring efficient process execution through metrics like turnaround time and waiting time. Additionally, it discusses the roles of the CPU scheduler and dispatcher in managing process states and context switching.

Uploaded by

chipmate8
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)
5 views47 pages

Final Term PPtT 1_ CPU Scheduling

The document provides an overview of CPU scheduling, detailing its fundamental concepts, types of schedulers, and various scheduling algorithms such as FCFS, SJF, and Round Robin. It emphasizes the importance of optimizing CPU utilization and ensuring efficient process execution through metrics like turnaround time and waiting time. Additionally, it discusses the roles of the CPU scheduler and dispatcher in managing process states and context switching.

Uploaded by

chipmate8
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/ 47

CPU SCHEDULING

LESSON GUIDE
CPU Scheduling
• Basic Concepts
• Process Schedulers
• Scheduling Criteria

CPU Scheduler
• Long Term Scheduler
• Medium Term Scheduler
• Short Term Scheduler
LESSON GUIDE
CPU Scheduling Algorithm
• First Come First Serve (FCFS)
• Shortest Job First (SJF)
• Shortest Remaining Time First (SRTF)
• Round Robin Scheduling (RR)
• Priority Scheduling (Prio)
• Preemptive Priority Scheduling
(PPrio)
CPU SCHEDULING
It is a fundamental function of an
operating system that manages how
processes are assigned CPU time. The
objective is to optimize CPU utilization
while ensuring that processes are
executed efficiently and fairly.
CPU SCHEDULING
Process Execution Cycle
CPU Burst:
This is the time during which a process is actively executing on the
CPU. CPU bursts can vary significantly between processes based
on their computational requirements.

I/O Burst:
This phase occurs when a process is waiting for I/O operations to
complete, such as reading from disk or waiting for user input.
Typically, I/O bursts are shorter than CPU bursts, and processes
frequently alternate between these two states.
CPU SCHEDULING
Process Execution Cycle
Final CPU Burst:
This refers to the last segment of CPU time required by a process
before it can terminate.
Upon completing this burst, the process releases its resources and
terminates.
CPU SCHEDULING
Basic Concepts

Process State
Context Switching
Time Quantum
Preemptive vs. Non-preemptive
Scheduling
CPU SCHEDULING
Basic Concepts

PROCESS STATE
Each process in an operating system can
be in one of several states, including new,
ready, running, waiting, and terminated.
The scheduler decides which process in
the ready state gets the CPU.
CPU SCHEDULING
Basic Concepts

CONTEXT SWITCHING
This is the process of saving the state of
a currently running process and loading
the state of the next scheduled process. It
incurs overhead, which can affect overall
system performance.
CPU SCHEDULING
Basic Concepts

TIME QUANTUM
In time-sharing systems, a time quantum
defines the maximum time a process can
run before being preempted. This helps
ensure fair CPU time allocation among
processes.
CPU SCHEDULING
Basic Concepts
Preemptive Scheduling: The operating
system can forcibly remove a process
from the CPU to allow another process to
run. This is essential for responsive
systems.
Non-preemptive Scheduling: Once a
process is given the CPU, it runs to
completion or voluntarily yields control.
This can lead to inefficiencies in systems
with varying process requirements.
CPU SCHEDULING
CPU Scheduler and Dispatcher

CPU Scheduler

The CPU scheduler is an integral part of the operating


system that decides which process will receive CPU
time at any given moment.
It uses various algorithms to make these decisions,
aiming to optimize performance metrics such as CPU
utilization and response time.
CPU SCHEDULING
CPU Scheduler and Dispatcher
Dispatcher

The dispatcher is the component that carries out the


scheduling decisions made by the CPU scheduler.

Its primary role is to switch the CPU from one process to


another, ensuring that the transition is smooth and
efficient.

Dispatch Latency
This term refers to the time taken by the dispatcher to
stop one process and start executing another.
CPU SCHEDULING
EVENT SCHEDULING
CPU scheduling occurs during specific events in a process’s
lifecycle:

1. Switching from Running to Waiting: When a process requires


I/O and must wait for the operation to complete.
2. Switching from Running to Ready: When a running process is
preempted (interrupted) to allow a higher-priority process to
execute.
3. Switching from Waiting to Ready: When an I/O operation is
completed, and the process is ready to run again.
4. Termination: When a process has completed its execution and
releases all resources.
CPU SCHEDULING
PROCESS SCHEDULER
Process scheduling involves different types of
schedulers that operate at various levels:

Long-term Scheduler (Job Scheduler)


Short-term Scheduler (CPU Scheduler)
Medium-term Scheduler
CPU SCHEDULING
PROCESS SCHEDULER
Long-term Scheduler (Job Scheduler)

• Function: Decides which processes are


admitted to the system for processing.
• Frequency: Executes less frequently, as it
controls the degree of multiprogramming.
• Goal: To maintain a balance between I/O and
CPU-bound processes.
CPU SCHEDULING
PROCESS SCHEDULER
Short-term Scheduler (CPU Scheduler)

• Function: Selects one of the processes in the


ready queue to be executed next.
• Frequency: Executes very frequently
(milliseconds).
• Goal: To maximize CPU utilization and ensure
quick response time.
CPU SCHEDULING
PROCESS SCHEDULER
Medium-term Scheduler:
• Function: Handles swapping processes in
and out of memory. This is crucial for
managing multiprogramming.
• Frequency: Less frequent than the short-term
scheduler.
• Goal: To optimize memory usage and
performance by balancing between I/O and
CPU-bound processes.
CPU SCHEDULING
SCHEDULING EFFICIENCY
To evaluate the efficiency of a CPU scheduling algorithm, several
key metrics are considered:

CPU Utilization
This measures the percentage of time the CPU is actively working.
High CPU utilization is desirable, as it indicates that the CPU is not
idle.

Throughput
This refers to the number of processes completed per unit of time.
Higher throughput indicates a more efficient system.
CPU SCHEDULING
SCHEDULING EFFICIENCY
Turnaround Time:
This is the total time taken from the submission of a process to its
completion, including waiting, execution, and I/O times.

Waiting Time:
The total time a process spends waiting in the ready queue before
it gets CPU time.

Response Time:
This is the time from when a request is submitted until the first
response is produced. It is particularly important for interactive
processes..
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
First Come First Serve (FCFS)
FCFS is the simplest CPU scheduling algorithm. Processes are
executed in the order they arrive in the ready queue.

Advantages:
Simple to implement and understand.
Fair in the sense that every process gets served in the order it
arrives.

Disadvantages:
Can lead to the "convoy effect," where short processes wait for
long processes to complete, resulting in high average waiting time.
Not suitable for time-sharing systems where response time is
critical.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Shortest Remaining Time First (SRTF)
SRTF is the preemptive version of SJF. If a new process arrives with a
shorter remaining time than the currently running process, the CPU is
preempted.

Advantages:
Reduces average waiting time and turnaround time compared to SJF.
More responsive for short jobs in interactive environments.

Disadvantages:
Increased overhead due to frequent context switching.
Still suffers from the potential for starvation.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Round Robin Scheduling (RR)
Round Robin scheduling assigns a fixed time slice (quantum) to each
process in the ready queue. If a process does not finish in its allotted
time, it is placed at the end of the queue.

Advantages:
Fair and ensures all processes receive CPU time.
Good for time-sharing systems, providing responsiveness.

Disadvantages:
The performance is heavily dependent on the time quantum size. A
very small quantum can lead to excessive context switching, while a
large quantum can behave like FCFS.
Average waiting time can be higher than SJF or SRTF.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Priority Scheduling (Prio)
Processes are assigned priorities, and the CPU is allocated to the
process with the highest priority. Lower numerical values often denote
higher priority.

Advantages:
Flexible; allows critical processes to be prioritized.
Useful in real-time systems where certain tasks must be completed
promptly.

Disadvantages:
Can lead to starvation if low-priority processes are perpetually
preempted by higher-priority processes.
Implementation complexity increases with dynamic priority changes.
CPU SCHEDULING
CPU SCHEDULING ALOGORITHM
Preemptive Priority Scheduling (PPrio)
This is a preemptive version of priority scheduling. If a new process
arrives with a higher priority than the currently running process, it
preempts the CPU.

Advantages:
Ensures that high-priority tasks are executed immediately, improving
response times for critical tasks.
Reduces the likelihood of starvation with appropriate mechanisms.

Disadvantages:
Increased context switching can lead to overhead.
Complexity in managing priority levels and avoiding starvation.
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Arrival Time
Queue Arrival Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 5
P2 1 3
P3 2 8
P4 3 6

P1 P2 P3 P4
0 5 8 16 22
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Arrival Time
Queue Arrival Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 5 5 5 0
P2 1 3 8 7 4
P3 2 8 16 14 6
P4 3 6 22 19 13

P1 P2 P3 P4
0 5 8 16 22
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Arrival Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 2 2 4 2 0 0
P2 0 1 1 1 0 0
P3 2 3 7 5 2 2
P4 3 5 12 9 4 4
P5 4 4 16 12 8 8

P2 P1 P3 P4 P5
0 1 2 4 7 12 16
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Priority Time
Queue Priority Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 3 17
P2 2 3
P3 1 6
P4 4 2

P3 P2 P1 P4
0 6 9 26 28
CPU SCHEDULING
SCHEDULING ALGORITHM
First Come First Serve (FCFS)
Mode:Non-Preemptive / Priority Time
Queue Priority Burst Completion Turn Around Time Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 3 17 26 26 9
P2 2 3 9 9 6
P3 1 6 6 6 0
P4 4 2 28 28 26

P3 P2 P1 P4
0 6 9 26 28
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 2 1
P2 1 5
P3 4 1
P4 0 6
P5 2 3

P4 P1 P3 P5 P2
0 6 7 8 11 16
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 2 1 7 5 4 4
P2 1 5 16 15 10 10
P3 4 1 8 4 3 3
P4 0 6 6 6 0 0
P5 2 3 11 9 6 6

P4 P1 P3 P5 P2
0 6 7 8 11 16
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
P5 4 6

P1 P2 P4 P5 P3
0 8 12 17 23 32
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completi Turn Around Waiting Response
Time Time on Time Time (CT-AT) ((TAT-BT) Time
P1 0 8 8 8 0 0
P2 1 4 12 11 7 7
P3 2 9 32 30 21 21
P4 3 5 17 14 9 9
P5 4 6 23 19 13

P1 P2 P4 P5 P3
0 8 12 17 23 32
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 3 4
P3 4 5
P4 6 3
P5 10 2

P1 P2 P4 P5 P1 P3
0 3 7 10 12 17 22
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 1 1
P3 2 3
P4 3 2
P5 4 6
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8 20 20 12 0
P2 1 1 2 1 0 0
P3 2 3 5 3 0 0
P4 3 2 7 4 2 2
P5 4 6 13 9 3 3
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Job First (SJF)
Mode:Non-Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 3 1
P2 1 4
P3 4 2
P4 0 6
P5 2 3
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 2 1 3
P2 1 5 16
P3 4 1 5
P4 0 6 11
P5 2 3 7
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8
P2 1 4
P3 2 2
P4 3 1
P5 4 3
P6 5 2
CPU SCHEDULING
SCHEDULING ALGORITHM
Shortest Remaining Job First (SRJF)
Mode:Preemptive / Burst Time
Queue Arrival Burst Completion Turn Around Waiting Response
Time Time Time Time (CT-AT) ((TAT-BT) Time
P1 0 8 20 20 12
P2 1 4 10 9 5
P3 2 2 4 2 0
P4 3 1 5 2 1
P5 4 3 13 9 6
P6 5 2 7 2 0
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Time Quantum: 5
Queue Arrival Burst Time Completion Turn Around Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 21
P2 0 3
P3 0 6
P4 0 2
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Arrival Time
Queue Arrival Burst Time Completion Turn Around Waiting
Time Time Time (CT-AT) ((TAT-BT)
P1 0 21
P2 0 3
P3 0 6
P4 0 2
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Time Quantum: 2

Queue Arrival Burst Time Completion Turn Around Waiting


Time Time Time (CT-AT) ((TAT-BT)
P1 0 5
P2 1 4
P3 2 2
P4 4 1
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Arrival Time

Queue Arrival Burst Time Completion Turn Around Waiting


Time Time Time (CT-AT) ((TAT-BT)
P1 0 5 12 12 7
P2 1 4 11 10 6
P3 2 2 6 4 2
P4 4 1 9 5 4
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Arrival Time
Queue Arrival Burst Completion Turn Around Waiting
Time Time Time Time (CT-AT) ((TAT-BT)
P1 0 4
P2 1 5
P3 2 2
P4 3 1
P5 4 6
P6 5 3
CPU SCHEDULING
SCHEDULING ALGORITHM
Round Robin Scheduling (RR)
Mode:Preemptive / Arrival Time

Queue Arrival Time Burst Time Completion Turn Around Waiting


Time Time (CT-AT) ((TAT-BT)
P1 0 4 8 8 4
P2 1 5 18 17 12
P3 2 2 6 4 2
P4 3 1 9 6 5
P5 4 6 21 17 11
P6 5 3 19 14 11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy