0% found this document useful (0 votes)
511 views

Multiple Tasks and Multiple Processes-Preemptive RTOS

The document discusses priority scheduling algorithms in operating systems. It describes preemptive and non-preemptive priority scheduling, and how preemptive priority scheduling allows higher priority processes to preempt lower priority processes. It also discusses types of priority scheduling, characteristics of priority scheduling, and solutions to the problem of priority inversion.

Uploaded by

msurendiran
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)
511 views

Multiple Tasks and Multiple Processes-Preemptive RTOS

The document discusses priority scheduling algorithms in operating systems. It describes preemptive and non-preemptive priority scheduling, and how preemptive priority scheduling allows higher priority processes to preempt lower priority processes. It also discusses types of priority scheduling, characteristics of priority scheduling, and solutions to the problem of priority inversion.

Uploaded by

msurendiran
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/ 32

Multiple tasks and multiple

processes- Preemptive RTOS


Priority Scheduling Algorithm in Operating System

 Priority Scheduling is a process scheduling algorithm based on priority


where the scheduler selects tasks according to priority. Thus, processes
with higher priority execute first followed by processes with lower
priorities.
 If two jobs have the same priorities then the process that should execute
first is chosen on the basis of round-robin or FCFS. Which process should
have what priority depends on a process’ memory requirements, time
requirements, the ratio of I/O burst to CPU burst, etc.
Priority Scheduling Algorithm in Operating
System
Types of Priority Scheduling

 The two main types of priority scheduling:


 Preemptive Scheduling
 Non-Preemptive Scheduling
What is preemptive priority based scheduling?

 Preemptive Priority CPU Scheduling Algorithm is a pre-emptive method


of CPU scheduling algorithm that works based on the priority of a process.
 In this algorithm, the scheduler schedules the tasks to work as per the
priority, which means that a higher priority process should be executed first.
What is preemptive priority based scheduling?

 In case a lower priority task is running and a higher priority task arrives in
the waiting state then the lower priority task is put on hold.
 The higher priority task replaces it and once done executing the lower
priority task resumes execution from when it was paused. This process
requires special hardware like a timer.
 Algorithms that are backed by preemptive Scheduling are round-robin (RR),
priority, SRTF (shortest remaining time first).
Non-Preemptive Scheduling

 The OS allocates the CPU to a specific process that releases the CPU
either through context switching or after termination.
 We can use this method on various hardware platforms because unlike
preemptive scheduling it doesn’t require any special hardware.
 Algorithms that are based on non-preemptive Scheduling are non-
preemptive priority, and shortest Job first.
Preemptive Vs Non-Preemptive Scheduling
Characteristics of Priority Scheduling

 Schedules processes on the basis of priority.


 Used to perform batch processes.
 In the case of two processes with similar priorities, we use FCFS and Round-
Robin to choose between them.
 A number is given to each process to indicate its priority level.
 Lower is the number assigned, higher is the priority level of a process.
 If a higher priority task arrives when a lower priority task is executing, the
higher priority task replaces the one with lower priority
Scheduling Algorithms

 Scheduling Algorithms include:


 First-Come-First-Served
 Shortest Job First
 Round Robin
 Priority
 Guaranteed
 Lottery
 Real-Time
IMPORTANT PARAMETERS

 Completion Time is the time required by the process to complete its execution
 Turnaround Time is the time interval between the submission of a process and its
completion.
Turnaround Time = completion of a process – submission of a process
 Waiting Time is the difference between turnaround time and burst time
Waiting Time = turnaround time – burst time
Example of Priority Scheduling

 Following five processes have a unique priority, burst time, and arrival time.
ANALYSIS
ANALYSIS
ANALYSIS
ANALYSIS
Shortest job first scheduling

 Shortest job first scheduling is the job or process scheduling algorithm that
follows the nonpreemptive scheduling discipline.
 In this, scheduler selects the process from the waiting queue with the least
completion time and allocate the CPU to that job or process.
 Shortest Job First is more desirable than FIFO algorithm because SJF is more
optimal as it reduces average wait time which will increase the throughput.
Shortest job first scheduling

 SJF algorithm can be preemptive as well as non-preemptive. Preemptive


scheduling is also known as shortest-remaining-time-first scheduling.
 In Preemptive approach, the new process arises when there is already executing
process.
 If the burst of newly arriving process is lesser than the burst time of executing
process than scheduler will preempt the execution of the process with lesser
burst time.
Shortest job first scheduling- Example
Shortest job first scheduling- Example
First-Come-First-Served

 First-Come-First-Served Algorithm is the simplest CPU


scheduling.
 Whichever process requests the CPU first gets it first.
 It is implemented using a standard FIFO single queue.
 Waiting time can be long and it depends heavily on the order in
which processes request CPU time
First-Come-First-Served - EXAMPLE
Round Robin Scheduling

 Round robin is a CPU scheduling algorithm that is designed especially for time
sharing systems.
 It is more like a FCFS scheduling algorithm with one change that in Round
Robin processes are bounded with a quantum time size. A small unit of time is
known as Time Quantum or Time Slice.
 Time quantum can range from 10 to 100 milliseconds. CPU treat ready queue
as a circular queue for executing the processes with given time slice.
 It follows preemptive approach because fixed time are allocated to processes.
The only disadvantage of it is overhead of context switching.
Round Robin Scheduling- Example
Round Robin Scheduling- Example
Priority Inversion

 Priority inversion is a operating system scenario in which a higher


priority process is preempted by a lower priority process. This implies the
inversion of the priorities of the two processes.
Problems due to Priority Inversion

 A system malfunction may occur if a high priority process is not provided the
required resources.
 Priority inversion may also lead to implementation of corrective measures. These
may include the resetting of the entire system.
 The performance of the system can be reduces due to priority inversion. This
may happen because it is imperative for higher priority tasks to execute
promptly.
Problems due to Priority Inversion

 System responsiveness decreases as high priority tasks may have strict time
constraints or real time response guarantees.
 Sometimes there is no harm caused by priority inversion as the late execution of
the high priority process is not noticed by the system.
Solutions of Priority Inversion

 Priority Ceiling
All of the resources are assigned a priority that is equal to the highest priority of
any task that may attempt to claim them. This helps in avoiding priority
inversion.
 Disabling Interrupts
There are only two priorities in this case i.e. interrupts disabled and preemptible.
So priority inversion is impossible as there is no third option.
Solutions of Priority Inversion

 Priority Inheritance
This solution temporarily elevates the priority of the low priority task that is
executing to the highest priority task that needs the resource. This means that
medium priority tasks cannot intervene and lead to priority inversion.
 No blocking
Priority inversion can be avoided by avoiding blocking as the low priority task
blocks the high priority task.
Advantages of priority scheduling in OS

 Easy to use.
 Processes with higher priority execute first which saves time.
 The importance of each process is precisely defined.
 A good algorithm for applications with fluctuating time and
resource requirements.
Disadvantages of priority scheduling in OS

 We can lose all the low-priority processes if the system crashes.


 This process can cause starvation if high-priority processes take
too much CPU time. The lower priority process can also be
postponed for an indefinite time.
 There is a chance that a process can’t run even when it is ready as
some other process is running currently.

You might also like