0% found this document useful (0 votes)
14 views11 pages

Scheduling 2 12

CPU scheduling is essential for efficient process execution in operating systems, involving the selection of processes from a ready queue based on various algorithms. Key algorithms include First-Come-First-Serve (FCFS), Shortest Job First (SJF), and Multilevel Queue Scheduling, each with distinct advantages and disadvantages affecting system performance. The choice of scheduling algorithm is critical for optimizing CPU utilization and ensuring timely execution of high-priority tasks.

Uploaded by

sukanta.csegmit
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)
14 views11 pages

Scheduling 2 12

CPU scheduling is essential for efficient process execution in operating systems, involving the selection of processes from a ready queue based on various algorithms. Key algorithms include First-Come-First-Serve (FCFS), Shortest Job First (SJF), and Multilevel Queue Scheduling, each with distinct advantages and disadvantages affecting system performance. The choice of scheduling algorithm is critical for optimizing CPU utilization and ensuring timely execution of high-priority tasks.

Uploaded by

sukanta.csegmit
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/ 11

Introduction to CPU Scheduling

CPU Scheduling is a fundamental concept in operating systems that ensures efficient


execution of processes. Here's a detailed breakdown of the points mentioned:
1. Selecting a Process from the Ready Queue:
o The operating system maintains a ready queue that holds processes waiting for CPU
execution.
o The CPU scheduler picks one process from this queue based on a scheduling
algorithm.
2. Optimizing CPU Utilization & System Performance:
o The goal is to keep the CPU as busy as possible to maximize efficiency.
o Proper scheduling reduces idle time, leading to better system performance.
o It helps in achieving faster response time for user applications.
3. Scheduling Algorithms:
o Various algorithms are used to decide the execution order of processes.
o Common types include First-Come-First-Serve (FCFS), Shortest Job First (SJF),
Round Robin (RR), and Multilevel Queue Scheduling.
o The choice of algorithm affects system performance in terms of waiting time,
turnaround time, and fairness.
Why is CPU Scheduling Important?
• Without scheduling, processes might execute inefficiently, leading to long waiting times
and CPU underutilization.
• It ensures that high-priority or time-sensitive tasks get executed on time, improving 2
system responsiveness.
First-Come, First-Served (FCFS)
Scheduling
Definition:
• FCFS is the simplest CPU scheduling algorithm where the process that arrives first
in the ready queue is executed first.
• It follows a FIFO (First In, First Out) approach, similar to a queue system.
Characteristics:
● Non-Preemptive: Once a process starts execution, it cannot be interrupted until it
completes.
● Simple & Easy to Implement: Requires minimal overhead and works in a
straightforward manner.
● Convoy Effect: If a longer process arrives first, it delays shorter processes, leading
to inefficiency.
Advantages:
● Fair scheduling as each process gets executed in order of arrival.
● Suitable for batch processing systems where execution order doesn’t impact user
experience.
Disadvantages:
● Poor response time for short processes if a long process arrives first.
● Low CPU utilization in some cases due to the convoy effect. 3
Example of FCFS Scheduling
Given Process Table:
Process Arrival Time Burst Time
P1 0 5
P2 1 3
P3 2 8
Execution Order:
• Since P1 arrives first, it executes first, followed by P2 and then P3.
Gantt Chart Representation:
| P1 | P2 | P3 |
0 5 8 16
Calculation of Important Metrics:
• Completion Time (CT): Time at which process execution ends.
• Turnaround Time (TAT) = CT - Arrival Time
• Waiting Time (WT) = TAT - Burst Time

Process CT TAT (CT - AT) WT (TAT - BT)


P1 5 5-0=5 5-5=0
P2 8 8-1=7 7-3=4
P3 16 16 - 2 = 14 14 - 8 = 6

• Convoy effect: If P1 had a very large burst time, P2 and P3 would wait longer, leading to
4
inefficiency.
Shortest Job First (SJF)
Scheduling
Definition:
• SJF is a CPU scheduling algorithm where the process with the shortest burst time is executed first.
• It is an optimal algorithm for minimizing average waiting time, but it requires knowing burst time in
advance.
Types of SJF:
1️⃣ Non-Preemptive SJF:
• Once a process starts execution, it cannot be interrupted until it finishes.
• It follows a greedy approach by selecting the shortest available job.
• Risk: Long waiting times for longer processes if many short processes arrive.
2️⃣ Preemptive SJF (Shortest Remaining Time First - SRTF):
• If a new process arrives with a shorter burst time than the currently executing process, the CPU
switches to the new process.
• Ensures better response time but has higher context switching overhead.
Advantages:
● Minimizes waiting time and turnaround time efficiently.
● Preemptive SJF (SRTF) provides better responsiveness in a multi-user environment.
Disadvantages:
● Difficult to implement as it requires predicting burst time.
● Starvation problem: Long processes might never execute if short jobs keep arriving (especially in
5
SRTF).
Example of Non-Preemptive
SJF
Given Processes :
Process Arrival Time Burst Time
P1 0 7
P2 1 3
P3 2 5

Execution Process:
1️⃣ At t = 0, only P1 is available, so it should start execution.
2️⃣ At t = 1, P2 arrives, and its burst time (3) is shorter than P1’s (7). So, the CPU
switches to P2 when it gets free.
3️⃣ At t = 4, P3 arrives, and its burst time (5) is shorter than P1 (7), so it executes next.
4️⃣ Finally, P1 executes last.
Execution Order (Non-Preemptive SJF):
P2 → P3 → P1
Gantt Chart Representation:
| P2 | P3 | P1 |
1 4 9 16
6
Example of Preemptive SJF
(SRTF)
Given Processes :
Process Arrival Time Burst Time
P1 0 8
P2 1 4
P3 2 9
P4 3 5
Execution Process (Shortest Remaining Time First - SRTF):
1️⃣ At t = 0, only P1 is available, so it starts execution.
2️⃣ At t = 1, P2 arrives (burst time = 4, shorter than P1’s remaining 7), so CPU switches
to P2.
3️⃣ At t = 3, P4 arrives (burst time = 5). Since P2 is still shorter, it continues.
4️⃣ At t = 5, P2 finishes, and the CPU switches to P4 (shortest remaining time).
5️⃣ At t = 8, P1 resumes execution since it's shorter than P3.
6️⃣ At t = 16, P1 finishes, and P3 executes last.
Final Execution Order:
P1 → P2 → P4 → P1 → P3
Gantt Chart Representation:
| P1 | P2 | P4 | P1 | P3 |
7
0 1 5 10 16 25
Multilevel Queue Scheduling
Definition: Multilevel Queue Scheduling is a CPU scheduling method where processes
are categorized into multiple queues based on their characteristics, such as priority,
process type, or resource needs. Each queue follows a specific scheduling algorithm.
Types of Queues:
1. Foreground Queue (Interactive Processes)
• Handles user applications, real-time tasks, and interactive processes.
• Uses Round Robin (RR) or Shortest Job Next (SJN) scheduling.
2. Background Queue (Batch Processes)
• Handles system processes, long-running tasks, and background jobs.
• Uses First-Come, First-Served (FCFS) or Priority Scheduling.
Scheduling Strategies:
● Fixed Priority Scheduling:
• Higher-priority queues execute first.
• Lower-priority queues only run when higher ones are empty.
• May lead to starvation for lower-priority processes.
● Time-Sharing Between Queues:
• CPU time is divided among queues.
• Prevents starvation by allocating fixed CPU time to lower-priority queues.
● Key Advantages:
• Efficient process categorization for better system performance.
• Different scheduling policies can be used for different types of tasks. 8

• Ensures priority-based execution while allowing fair CPU distribution.


Example of Multilevel Queue
Scheduling
Queue Structure:
1️⃣ Queue 1 (Foreground - Interactive Processes)
• Uses Round Robin (RR) Scheduling for quick response.
• Handles tasks like real-time applications, GUI programs, and user requests.
2️⃣ Queue 2 (Background - Batch Processes)
• Uses First-Come, First-Served (FCFS) Scheduling for simplicity.
• Handles tasks like system updates, background computations, and batch jobs.
Example Execution:
Step 1: High-priority interactive process P1 (GUI application) arrives → Assigned to
Queue 1 (executed using RR).
Step 2: Another interactive process P2 arrives → It shares CPU time with P1 in
Queue 1.
Step 3: A batch process P3 (long background job) arrives → Assigned to Queue 2,
waiting for Queue 1 to become idle.
Step 4: When P1 & P2 complete or reach their time slice, CPU allocates time to P3
(executed using FCFS).
Key Takeaways:
o Interactive tasks get quick responses, ensuring better user experience.
o Batch jobs execute efficiently without interrupting critical processes. 9
o CPU utilization is maximized by distributing tasks into different queues.
Advantages & Disadvantages of
Scheduling Algorithms
First-Come, First-Served (FCFS):
● Advantages:
• Simple and easy to implement.
• Works well for batch systems with long processes.
● Disadvantages:
• Convoy Effect: Short processes may have to wait for long processes to finish.
• Poor turnaround time in cases where longer processes arrive first.
Shortest Job First (SJF):
● Advantages:
• Minimizes average waiting time.
• Efficient for reducing turnaround time.
● Disadvantages:
• Requires precise knowledge of burst time, which is difficult to predict.
• Starvation: Long processes may be delayed indefinitely if shorter processes keep arriving.
Multilevel Queue Scheduling:
● Advantages:
• Efficient for handling processes with different priorities.
• Ensures interactive processes get quick response times.
● Disadvantages:
• Complex to manage multiple queues and scheduling policies. 10

• Low-priority processes may face starvation if not managed properly.


Conclusion
❖ CPU Scheduling plays a crucial role in optimizing system performance
and efficient resource utilization.

❖ Different scheduling algorithms (FCFS, SJF, and Multilevel Queue


Scheduling) have their own advantages and are suited for different
types of workloads.

❖ FCFS is simple but may cause longer wait times due to the Convoy
Effect.

❖ SJF minimizes waiting time but can lead to starvation for longer
processes.

❖ Multilevel Queue Scheduling efficiently handles different priority


processes but adds complexity to management.

❖ The choice of scheduling algorithm depends on factors like process


priority, burst time predictability, and system requirements to
ensure optimal performance. 11
12

You might also like