Difference Between Preemptive And Non-Preemptive Scheduling

Unstop
7 min readMar 22, 2022

--

Table of content:

  • What is the purpose of CPU scheduling?
  • What is preemptive scheduling?
  • What is non-preemptive scheduling method?
  • Difference Between Preemptive and Non-Preemptive Scheduling

Scheduling in a CPU 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.

ALSO READ

Understanding The Basic Concept Of Structural Testing

What is the purpose of CPU scheduling?

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

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 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. Preemptive Scheduling 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), etc.

Let us understand with an example of the shortest job first scheduling.

The data is given as-

The Gantt chart for preemptive of SJF technique can be made as-

Thus the average waiting time for each process can be calculated.

ALSO READ

Understanding The Difference Between Functional and Non-Functional Testing

What is 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 then continues when 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, 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)

For the above-mentioned example, the Gantt chart for non-preemptive scheduling is as follows.

Here, no other process can enter until the previous process(now which has a lesser arrival time) has been completed.

And the average waiting time for each process as-

Clearly, preemptive takes less time than non-preemptive.

Difference Between Preemptive and Non-Preemptive Scheduling

ParameterPREEMPTIVE SCHEDULINGNON-PREEMPTIVE SCHEDULINGMeaningFor 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.InterruptThe process can be halted at any time.The process can’t be stopped until it finishes or its timer runs out.StarvationA 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.OverheadIt contains overheads of switching a process from running state to ready stateThere are no overheads.FlexibilityflexiblerigidCostcost associatedno cost associatedCPU UtilizationCPU is overworkedCPU is less utilizedExamplesRound Robin and Shortest Remaining Time First are two examples of preemptive scheduling.First come, first served, and the quickest job gets done first.TimeWaiting and Response time is lower

Waiting and response time is higher

Basic difference between the two scheduling techniques

  1. 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.
  2. 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.
  3. The overhead of moving the process from ready to running state, and vice versa, as well as maintaining the ready queue, is incurred by preemptive scheduling. Non-preemptive scheduling, on the other hand, avoids the overhead of transitioning a process from running to a ready state.
  4. 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. 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.
  5. 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. Non-preemptive scheduling is strict because even if a vital process joins the ready queue, the CPU of the executing process is not affected.
  6. Preemptive Scheduling is cost associative because it must preserve the integrity of shared data, whereas Non-preemptive Scheduling does not have to do.

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

Advantages of Preemptive Sheduling

  • Preemptive scheduling is a more robust solution that prevents one process from monopolising 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 programmes 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.

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.

ALSO READ

What Is Evolutionary Model In Software Engineering?

Summing up…

We know that non-preemptive type of schedule, has no overhead of transferring processes from ready queue to CPU, but it does make scheduling inflexible because the process now in execution is not even preempted for a higher priority process. It’s not a case of preemptive scheduling being better than non-preemptive scheduling or vice versa. It all relies on how a scheduling algorithm reduces average process waiting time while increasing CPU usage.

You might also be interested in reading:

  1. What Is Paging In Operating System?
  2. Difference Between JavaScript And jQuery
  3. 10 Best React Projects Ideas You Must Build in 2022
  4. Difference Between Hardware and Software

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Unstop
Unstop

Written by Unstop

Unstop (formerly Dare2Compete) enables companies to engage with candidates in the most interactive way to discover, assess, and hire the best talent.

No responses yet

What are your thoughts?