Home Computer Science Difference Between Preemptive And Non-Preemptive Scheduling

Difference Between Preemptive And Non-Preemptive Scheduling

CPU scheduling is a task that involves planning and arranging processes in various stages such as 'ready', 'waiting', and 'running'. It enables the operating system to assign a time period for CPU execution to each process, allowing it to pick which tasks to do and for how long. This scheduling of CPU can be done in two ways: preemptive and non-preemptive scheduling. In this article, we will take you through these two types of scheduling. Toward the end, we will discuss the difference between preemptive and non-preemptive scheduling. 

What is the purpose of CPU scheduling?

I/O and CPU time are both used in a typical process. The time spent waiting for input and output in a unified programming system like MS-DOS is wasted, and the CPU is free during that time. One process can use the CPU while another waits for I/O in multiprogramming systems. Thus CPU scheduling the processor helps in multitasking.

What is preemptive scheduling?

When the CPU is idle, it is the role of the CPU scheduler to assign a task to it. The CPU scheduler chooses a process from the ready queue and assigns it to the CPU. If there is still CPU burst time left, the resources (CPU cycles) are assigned to the critical process for a short period and then removed, and the process is placed back in the ready queue. The process remains in the ready queue until it is given the opportunity to run again. 

Preemptive Scheduling is the scheduling that occurs when a process transitions from a running state to a ready state or from a waiting state to a ready state. It is a style of scheduling in which jobs are largely assigned according to their priority. 

When a high-priority process enters the ready queue, it is not required to wait for the current process to finish its burst period. Instead, the current process is paused in the middle of execution and placed in the ready queue until the high-priority process consumes all CPU cycles. As a result, each task in the ready queue gets some CPU time. It increases the overhead of transitioning the process from running to ready state and vice versa, but it makes preemptive scheduling more flexible.

Examples of preemptive scheduling algorithms

Some scheduling algorithms based on preemptive scheduling are-

  • Round Robin (RR)
  • Shortest Remaining Time First (SRTF)
  • Priority (preemptive version)

What is a non-preemptive scheduling method?

Even though the lower-priority activity is still running, it is sometimes necessary to run a higher-priority task before a lower-priority task. The lower-priority work is put on hold for a while and resumes after the higher-priority activity is completed. The non-preemptive scheduling process is the type of scheduling that occurs when a process quits or shifts from executing to waiting for the state.

The CPU has been assigned to a certain process in this scheduling mechanism. The process that keeps the CPU occupied will either switch context or terminate to relieve the CPU. When a process voluntarily enters the wait state or terminates, this is known as non-preemptive scheduling.

If a process with a long CPU burst time is running under non-preemptive scheduling, it is not interrupted in the middle of execution and the other process will have to wait for a long period, increasing the average waiting time of the processes in the ready queue.

Examples of non-preemptive scheduling -

Some scheduling algorithms based on preemptive scheduling are-

  • Shortest Job First (SJF, which is essentially non-preemptive)
  • First-come-first-served
  • Priority (non-preemptive version)

Comparison between preemptive and non-preemptive scheduling 

Parameter PREEMPTIVE SCHEDULING NON-PREEMPTIVE SCHEDULING
Meaning For a limited time, resources (CPU Cycle) are allotted to a process. Once resources (CPU Cycles) are allotted to a process, it is held until the burst time is completed or the process transitions to the waiting state.
Interrupt The process can be halted at any time. The process can't be stopped until it finishes or its timer runs out.
Starvation A low-priority process may starve if a high-priority process often appears in the ready queue. If a process with a long burst time consumes CPU, subsequent processes with shorter burst times may suffer.
Overhead It contains overheads of switching a process from running state to ready state There are no overheads.
Flexibility Flexible Rigid
Cost Cost associated No cost associated
CPU Utilization CPU is overworked CPU is less utilized
Examples Round Robin and Shortest Remaining Time First are two examples of preemptive scheduling. First come, first served, and the quickest job gets done first.
Time Waiting and response time is lower

Waiting and response time is higher

Basic differences between the preemptive and non-preemptive scheduling techniques

Preemptive scheduling differs from non-preemptive scheduling in that the CPU is allotted to the processes for a set amount of time in preemptive scheduling. The CPU is allotted to the process in non-preemptive scheduling until it quits or changes to the waiting state.

Consequently, in preemptive scheduling, the execution process is interrupted in the middle, whereas in non-preemptive scheduling, the execution process is not stopped in the middle. Moreover, in preemptive scheduling, if a high-priority process repeatedly appears in the ready queue, the low-priority process will have to wait a long time and may have to starve. However, because vital processes are permitted to access the CPU when they arrive in the ready queue, regardless of what task is presently running, preemptive scheduling is extremely flexible.

In non-preemptive scheduling, on the other hand, if the CPU is allotted to the process with the longer burst time, the processes with the shorter burst time may be forced to starve. Non-preemptive scheduling is strict because even if a vital process joins the ready queue, the CPU of the executing process is not affected.

Let us now discuss the advantages and disadvantages of these scheduling techniques, starting with preemptive scheduling:

Advantages of preemptive scheduling - 

  • Preemptive scheduling is a more robust solution that prevents one process from monopolizing the CPU.
  • After each interruption, the running job was reviewed.
  • Each occurrence resulted in the disruption of ongoing tasks.
  • The operating system ensures that all running processes use the same amount of CPU.
  • The CPU consumption is the same in this case, i.e., all running programs will consume the same amount of CPU.
  • The average response time is also improved by using this scheduling strategy.
  • When used in a multi-programming environment, preemptive scheduling is advantageous.

Disadvantages of preemptive scheduling

The following are the disadvantages and drawbacks of the Preemptive Scheduling method:

  • Scheduling necessitates the use of limited computational resources.
  • The scheduler spends more time suspending the ongoing job, switching the context, and dispatching the new incoming task.

  • If many high-priority processes arrive at the same time, the low-priority process will have to wait longer.

These are the advantages and disadvantages of non-preemptive scheduling:

Advantages of non-preemptive scheduling - 

  • Low overhead in terms of scheduling
  • It has a tendency to have a high throughput.
  • It is a fairly basic strategy in terms of principle.
  • Scheduling requires fewer computing resources.

Disadvantages of non-preemptive scheduling

  • It can lead to famine, especially for those jobs that require immediate attention.
  • Bugs can cause a system to become unresponsive.
  • It has the ability to make real-time and priority decisions. Scheduling is a challenge.
  • Process reaction time is too slow.

You might also be interested in reading:

  1. What Is Paging In Operating System?
  2. Difference Between JavaScript And jQuery
  3. Difference Between Hardware and Software
  4. Difference Between Hashing And Encryption Decoded
Umme Kulsum
Associate Content Writer @Unstop

I am a lifelong student of languages, English being the pet favorite, exploring my creative side through content writing. I also like to boogie. When I am not reading, binge-watching, and dancing, you can spot me doing pspspspspss to cats and dogs on the streets.

TAGS
Computer Science
Updated On: 19 Oct'23, 10:44 AM IST