Preemptive and Non-Preemptive Scheduling - GeeksforGeeks

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

29

Preemptive and Non-Preemptive Scheduling


Last Updated : 26 Sep, 2024

In operating systems, scheduling is the method by which processes are


given access to system resources, primarily the CPU. Efficient
scheduling is essential for optimal system performance and user
satisfaction. There are two primary types of CPU scheduling:
preemptive and non-preemptive.

Understanding the differences between preemptive and non-


preemptive scheduling helps in designing and choosing the right
scheduling algorithms for various types of operating systems. You will
discover the distinction between preemptive and non-preemptive
scheduling in this article. But first, you need to understand preemptive
and non-preemptive scheduling before going over the differences.

What is Preemptive Scheduling?


Preemptive scheduling is used when a process switches from the
running state to the ready state or from the waiting state to the ready
state. The resources (mainly CPU cycles) are allocated to the process for
a limited amount of time and then taken away, and the process is again
placed back in the ready queue if that process still has CPU burst time
remaining. That process stays in the ready queue till it gets its next
chance to execute.

Algorithms based on preemptive scheduling are Round Robin (RR) ,


Shortest Remaining Time First (SRTF) , Priority (preemptive version) ,
etc.
Preemptive Scheduling

In preemptive scheduling, the CPU can be interrupted, unlike in non-


preemptive scheduling. To gain a comprehensive understanding of
scheduling algorithms and proper resources for GATE preparation,
check out the GATE CS Self-Paced Course that covers these in detail.

Advantages of Preemptive Scheduling

Because a process may not monopolize the processor, it is a more


reliable method.
Each occurrence prevents the completion of ongoing tasks.
The average response time is improved.
Utilizing this method in a multi-programming environment is more
advantageous.
The operating system makes sure that every process using the CPU
is using the same amount of CPU time.

Disadvantages of Preemptive Scheduling

Limited computational resources must be used.


Suspending the running process, change the context, and dispatch
the new incoming process all take more time.
The low-priority process would have to wait if multiple high-priority
processes arrived at the same time.

What is Non-Preemptive Scheduling?


Non-preemptive Scheduling is used when a process terminates, or a
process switches from running to the waiting state. In this scheduling,
once the resources (CPU cycles) are allocated to a process, the process
holds the CPU till it gets terminated or reaches a waiting state. In the
case of non-preemptive scheduling does not interrupt a process running
CPU in the middle of the execution. Instead, it waits till the process
completes its CPU burst time, and then it can allocate the CPU to
another process.

Algorithms based on non-preemptive scheduling are: Shortest Job First


(SJF basically non preemptive) and Priority (nonpreemptive version) ,
etc.

Advantages of Non-Preemptive Scheduling

It has a minimal scheduling burden.


It is a very easy procedure.
Less computational resources are used.
It has a high throughput rate.

Aptitude Engineering Mathematics Discrete Mathematics Operating System


Disadvantages of Non-Preemptive Scheduling
DBMS Computer Netw

Its response time to the process is super.


Bugs can cause a computer to freeze up.
Key Differences Between Preemptive and Non-
Preemptive Scheduling
In preemptive scheduling, the CPU is allocated to the processes for a
limited time whereas, in Non-preemptive scheduling, the CPU is
allocated to the process till it terminates or switches to the waiting
state.
The executing process in preemptive scheduling is interrupted in the
middle of execution when a higher priority one comes whereas, the
executing process in non-preemptive scheduling is not interrupted in
the middle of execution and waits till its execution.
In Preemptive Scheduling, there is the overhead of switching the
process from the ready state to the running state, vise-verse, and
maintaining the ready queue. Whereas in the case of non-preemptive
scheduling has no overhead of switching the process from running
state to ready state.
In preemptive scheduling, if a high-priority process arrives in the
ready queue then the process with low priority has to wait for a long
time, and it may have to starve. In non-preemptive scheduling, if CPU
is allocated to the process having a larger burst time then the
processes with a small burst time may have to starve.
Preemptive scheduling attains flexibility by allowing the critical
processes to access the CPU as they arrive in the ready queue, no
matter what process is executing currently. Non-preemptive
scheduling is called rigid as even if a critical process enters the ready
queue the process running CPU is not disturbed.
Preemptive Scheduling has to maintain the integrity of shared data
that’s why it is cost associative which is not the case with Non-
preemptive Scheduling.

Parameter PREEMPTIVE NON-PREEMPTIVE


SCHEDULING SCHEDULING

Basic In this resources(CPU Once resources(CPU Cycle)


Cycle) are allocated to a are allocated to a process, the
process for a limited time. process holds it till it
Parameter PREEMPTIVE NON-PREEMPTIVE
SCHEDULING SCHEDULING

completes its burst time or


switches to waiting state

Process can not be interrupted


Process can be interrupted
Interrupt until it terminates itself or its
in between.
time is up

If a process having high


If a process with a long burst
priority frequently arrives
time is running CPU, then
Starvation in the ready queue, a low
later coming process with less
priority process may
CPU burst time may starve
starve

It has overheads of
Overhead It does not have overheads
scheduling the processes

Flexibility flexible Rigid

Cost Cost associated No cost associated

CPU In preemptive scheduling, It is low in non preemptive


Utilization CPU utilization is high scheduling

Waiting Preemptive scheduling Non-preemptive scheduling


Time waiting time is less waiting time is high

Response Preemptive scheduling Non-preemptive scheduling


Time response time is less response time is high

Decisions are made by the Decisions are made by the


Decision scheduler and are based process itself and the OS just
making on priority and time slice follows the process’s
allocation instructions
Parameter PREEMPTIVE NON-PREEMPTIVE
SCHEDULING SCHEDULING

The OS has greater


Process The OS has less control over
control over the
control the scheduling of processes
scheduling of processes

Higher overhead due to Lower overhead since context


Overhead
frequent context switching switching is less frequent

Examples of preemptive Examples of non-preemptive


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

Conclusion
Preemptive scheduling allows the operating system to interrupt and
reassign the CPU to different processes, making it responsive and
efficient for high-priority tasks. Non-preemptive scheduling lets
processes run to completion without interruption, simplifying the
system but potentially causing delays for other tasks. The choice
between these methods depends on the system’s needs for
performance and simplicity.

Preemptive and Non-Preemptive Scheduling – FAQs

How is priority determined in preemptive scheduling?

Preemptive scheduling systems often assign priority levels to


tasks or processes. The priority can be determined based on
factors like the nature of the task, its importance, or its deadline.
Higher-priority tasks are given precedence and are allowed to
execute before lower-priority tasks.
What happens in non-preemptive scheduling if a task does not yield
the CPU?

In non-preemptive scheduling, if a task does not voluntarily yield


the CPU, it can lead to a situation called a “starvation” or
“deadlock” where other tasks are unable to execute. To avoid such
scenarios, it’s important to ensure that tasks have mechanisms to
release the CPU when necessary, such as waiting for I/O
operations or setting maximum execution times.

Which scheduling method is better for real-time systems?

Preemptive scheduling is generally better for real-time systems


because it allows high-priority tasks to be addressed immediately,
meeting the time-sensitive requirements of such systems.

A Ankit… Follow 191

Previous Article Next Article


Context Switching in Operating CPU Scheduling in Operating Systems
System

Similar Reads
Difference between Preemptive Priority based and Non-preemptive…
Prerequisite - CPU Scheduling Priority Scheduling : In priority scheduling,
each process has a priority which is an integer value assigned to it. The…
4 min read

Difference Between Preemptive and Non-Preemptive CPU Scheduli…


Preemptive scheduling permits a high-priority task to interrupt a running
process, When a process transitions from the running to the ready or fro…
6 min read

Difference between Preemptive and Non-Preemptive Kernel in OS


Introduction : A kernel is the central component of an operating system
that manages system resources and provides a layer of abstraction…
4 min read

Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non-…
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…
13 min read

Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorith…


Shortest job first (SJF) or shortest job next, is a scheduling policy that
selects the waiting process with the smallest execution time to execute…
15+ min read

Relation in FCFS and Preemptive Priority Scheduling Algorithm


In this article, we will see how FCFS is a special kind of Priority
Preemptive Scheduling Algorithm. Also, we will cover the relation with…
4 min read

Relation between Preemptive Priority and Round Robin Scheduling…


In this article, we'll try to establish the relation between Round Robin and
Preemptive Priority Scheduling Algorithm. Let's discuss the algorithms…
2 min read

Program for Preemptive Priority CPU Scheduling


Implementing priority CPU scheduling. In this problem, we are using Min
Heap as the data structure for implementing priority scheduling. In this…
15+ min read

Longest Remaining Time First (LRTF) or Preemptive Longest Job Fir…


Longest Remaining Time First (LRTF) is a preemptive version of Longest
Job First (LJF) scheduling algorithm. In this scheduling algorithm, we find…
7 min read

Shortest Remaining Time First (Preemptive SJF) Scheduling…


In previous post, we have discussed Set 1 of SJF i.e. non-pre-emptive. In
this post we will discuss the pre-emptive version of SJF known as…
15+ min read

Article Tags :

GATE CS Operating Systems Technical Scripter Operating Systems-CPU Scheduling

Corporate & Communications Address:-


A-143, 9th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305) | Registered Address:- K 061,
Tower K, Gulshan Vivante Apartment,
Sector 137, Noida, Gautam Buddh
Nagar, Uttar Pradesh, 201305

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial

Data Science & ML Web Technologies


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning JavaScript
ML Maths TypeScript
Data Visualisation ReactJS
Pandas NextJS
NumPy NodeJs
NLP Bootstrap
Deep Learning Tailwind CSS

Python Tutorial Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Commerce


Mathematics Accountancy
Physics Business Studies
Chemistry Economics
Biology Management
Social Science HR Management
English Grammar Finance
Income Tax

Databases Preparation Corner


SQL Company-Wise Recruitment Process
MYSQL Resume Templates
PostgreSQL Aptitude Preparation
PL/SQL Puzzles
MongoDB Company-Wise Preparation
Companies
Colleges

Competitive Exams More Tutorials


JEE Advanced Software Development
UGC NET Software Testing
UPSC Product Management
SSC CGL Project Management
SBI PO Linux
SBI Clerk Excel
IBPS PO All Cheat Sheets
IBPS Clerk Recent Articles

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

You might also like