PNPS - aryanjoshi0823/5143-Operating-System GitHub Wiki

Here's the GitHub Wiki markdown version for your content:


Difference Between Preemptive and Non-Preemptive Scheduling

In this article, you will learn the difference between Preemptive and Non-Preemptive Scheduling. Before diving into the differences, let's understand each scheduling method.


What is Preemptive Scheduling?

Preemptive scheduling allows a running process to be interrupted and moved to the ready queue when a higher-priority process arrives. This method ensures critical processes are executed promptly.

  • The CPU is assigned to a process for a specific time slice. If the process's burst time isn't completed, it returns to the ready queue.
  • High-priority processes can preempt lower-priority ones, enhancing flexibility.

Example of Preemptive Scheduling

Process Arrival Time CPU Burst Time (ms)
P0 3 2
P1 2 4
P2 0 6
P3 1 4

Execution Steps:

  1. P2 arrives at time 0 and starts execution.
  2. At time 1, P3 arrives. Since its burst time (4 ms) is shorter than the remaining burst time of P2 (5 ms), the CPU switches to P3.
  3. At time 2, P1 arrives. However, P3 continues as its remaining time (3 ms) is shorter than P1's burst time (4 ms).
  4. At time 3, P0 arrives. Since P3's remaining time (2 ms) equals P0's burst time, P3 continues.
  5. After P3 finishes, P0, P1, and P2 execute sequentially based on their burst times.

What is Non-Preemptive Scheduling?

Non-preemptive scheduling ensures a running process completes its burst time or enters the waiting state before another process starts.

  • Processes cannot be interrupted during execution.
  • Simpler but less flexible than preemptive scheduling.

Example of Non-Preemptive Scheduling

Using the same processes as above:

Process Arrival Time CPU Burst Time (ms)
P0 3 2
P1 2 4
P2 0 6
P3 1 4

Execution Steps:

  1. P2 starts execution at time 0 and runs for 6 ms.
  2. Once P2 finishes, the next process (P3) executes, followed by P1 and P0, in the order of their arrival.

Key Differences Between Preemptive and Non-Preemptive Scheduling

Aspect Preemptive Scheduling Non-Preemptive Scheduling
Interruption Allows interruption of running processes. Processes cannot be interrupted once they start.
Flexibility More flexible and suitable for real-time systems. Less flexible and more rigid.
Starvation Low-priority processes may starve. Processes with shorter burst times may starve.
CPU Utilization Higher CPU utilization. Lower CPU utilization.
Overhead Higher due to frequent context switching. Minimal overhead.
Examples Round Robin, Shortest Remaining Time First. First Come First Serve (FCFS), Shortest Job First (SJF).
Suitability Suitable for time-critical tasks. Suitable for batch processing systems.
⚠️ **GitHub.com Fallback** ⚠️