Difference between Preemptive and Non-Preemptive Scheduling

In this article, you will learn the difference between preemptive and non-preemptive scheduling. But before discussing the differences, you need to know about preemptive and non-preemptive scheduling.

What is Preemptive Scheduling?

Preemptive scheduling is a method that may be used when a process switches from a running state to a ready state or from a waiting state to a ready state. The resources are assigned to the process for a particular time and then removed. If the resources still have the remaining CPU burst time, the process is placed back in the ready queue. The process remains in the ready queue until it is given a chance to execute again.

When a high-priority process comes in the ready queue, it doesn't have to wait for the running process to finish its burst time. However, the running process is interrupted in the middle of its execution and placed in the ready queue until the high-priority process uses the resources. As a result, each process gets some CPU time in the ready queue. It improves the overhead of switching a process from running to ready state and vice versa, increasing preemptive scheduling flexibility. It may or may not include SJF and Priority scheduling.

For example:

Let us take the example of Preemptive Scheduling. We have taken P0, P1, P2, and P3 are the four processes.

ProcessArrival TimeCPU Burst time (in millisec.)
P032
P124
P206
P314

Preemptive vs Non-Preemptive Scheduling
  • Firstly, the process P2 comes at time 0. So, the CPU is assigned to process P2.
  • When process P2 was running, process P3 arrived at time 1, and the remaining time for process P2 (5 ms) is greater than the time needed by process P3 (4 ms). So, the processor is assigned to P3.
  • When process P3 was running, process P1 came at time 2, and the remaining time for process P3 (3 ms) is less than the time needed by processes P1 (4 ms) and P2 (5 ms). As a result, P3 continues the execution.
  • When process P3 continues the process, process P0 arrives at time 3. P3's remaining time (2 ms) is equal to P0's necessary time (2 ms). So, process P3 continues the execution.
  • When process P3 finishes, the CPU is assigned to P0, which has a shorter burst time than the other processes.
  • After process P0 completes, the CPU is assigned to process P1 and then to process P2.

Advantages and disadvantages of Preemptive Scheduling

There are various advantages and disadvantages of Preemptive scheduling. The advantages and disadvantages of non-preemptive scheduling are as follows:

Advantages

  1. It is a more robust method because a process may not monopolize the processor.
  2. Each event causes an interruption in the execution of ongoing tasks.
  3. It improves the average response time.
  4. It is more beneficial when you use this method in a multi-programming environment.
  5. The operating system ensures that all running processes use the same amount of CPU.

Disadvantages

  1. It requires the use of limited computational resources.
  2. It takes more time suspending the executing process, switching the context, and dispatching the new incoming process.
  3. If several high-priority processes arrive at the same time, the low-priority process would have to wait longer.

What is Non-Preemptive Scheduling?

Non-preemptive scheduling is a method that may be used when a process terminates or switches from a running to a waiting state. When processors are assigned to a process, they keep the process until it is eliminated or reaches a waiting state. When the processor starts the process execution, it must complete it before executing the other process, and it may not be interrupted in the middle.

When a non-preemptive process with a high CPU burst time is running, the other process would have to wait for a long time, and that increases the process average waiting time in the ready queue. However, there is no overhead in transferring processes from the ready queue to the CPU under non-preemptive scheduling. The scheduling is strict because the execution process is not even preempted for a higher priority process.

For example:

Let's take the above preemptive scheduling example and solve it in a non-preemptive manner.

Preemptive vs Non-Preemptive Scheduling
  • The process P2 comes at 0, so the processor is assigned to process P2 and takes (6 ms) to execute.
  • All of the processes, P0, P1, and P3, arrive in the ready queue in between. But all processes wait till process P2 finishes its CPU burst time.
  • After that, the process that comes after process P2, i.e., P3, is assigned to the CPU until it finishes its burst time.
  • When process P1 completes its execution, the CPU is given to process P0.

Advantages and disadvantages of Non-preemptive Scheduling

There are various advantages and disadvantages of non-preemptive scheduling. The advantages and disadvantages of non-preemptive scheduling are as follows:

Advantages

  1. It provides a low scheduling overhead.
  2. It is a very simple method.
  3. It uses less computational resources.
  4. It offers high throughput.

Disadvantages

  1. It has a poor response time for the process.
  2. A machine can freeze up due to bugs.

Main Differences between the Preemptive and Non-Preemptive Scheduling

Preemptive vs Non-Preemptive Scheduling

Here, you will learn the main differences between Preemptive and Non-Preemptive Scheduling. Various differences between the Preemptive and Non-Preemptive Scheduling are as follows:

  1. In preemptive scheduling, the CPU is assigned to the processes for a particular time period. In contrast, the CPU is assigned to the process until it removes and switches to the waiting state.
  2. When a process with a high priority appears in the ready queue frequently in preemptive scheduling, the process with a low priority must wait for a long period and can starve. In contrast, when the CPU is assigned to the process with the high burst time, the processes with the shorter burst time can starve in non-preemptive scheduling.
  3. When a higher priority process comes in the CPU, the running process in preemptive scheduling is halted in the middle of its execution. On the other hand, the running process in non-preemptive scheduling doesn't interrupt in the middle of its execution and waits until it is completed.
  4. Preemptive scheduling is flexible in processing. On the other side, non-preemptive is strict.
  5. Preemptive scheduling is quite flexible because critical processes are allowed to access the CPU because they come in the ready queue and no matter which process is currently running. Non-preemptive scheduling is tough because if an essential process is assigned to the ready queue, the CPU process is not be interrupted.
  6. In preemptive scheduling, CPU utilization is more effective than non-preemptive scheduling. On the other side, in non-preemptive scheduling, the CPU utilization is not effective as preemptive scheduling.
  7. Preemptive scheduling is very cost-effective because it ensures the integrity of shared data. In contrast, it is not in the situation of non-preemptive scheduling.

Head-to-head Comparison between the Preemptive and Non-Preemptive Scheduling

Here, you will learn the head-to-head comparison between preemptive and non-preemptive scheduling. The main differences between preemptive and non-preemptive scheduling are as follows:

Preemptive SchedulingNon-Preemptive Scheduling
The resources are assigned to a process for a long time period.Once resources are assigned to a process, they are held until it completes its burst period or changes to the waiting state.
Its process may be paused in the middle of the execution.When the processor starts the process execution, it must complete it before executing the other process, and it may not be interrupted in the middle.
When a high-priority process continuously comes in the ready queue, a low-priority process can starve.When a high burst time process uses a CPU, another process with a shorter burst time can starve.
It is flexible.It is rigid.
It is cost associated.It does not cost associated.
It has overheads associated with process scheduling.It doesn't have overhead.
It affects the design of the operating system kernel.It doesn't affect the design of the OS kernel.
Its CPU utilization is very high.Its CPU utilization is very low.
Examples: Round Robin and Shortest Remaining Time FirstFCFS and SJF are examples of non-preemptive scheduling.

Conclusion

It's not a case of preemptive scheduling being superior to non-preemptive scheduling or vice versa. It all depends on how a scheduling algorithm reduces average process waiting time while increasing CPU utilization






Latest Courses