PNPS - aryanjoshi0823/5143-Operating-System GitHub Wiki
Here's the GitHub Wiki markdown version for your content:
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.
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.
Process | Arrival Time | CPU Burst Time (ms) |
---|---|---|
P0 | 3 | 2 |
P1 | 2 | 4 |
P2 | 0 | 6 |
P3 | 1 | 4 |
Execution Steps:
- P2 arrives at time 0 and starts execution.
- 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.
- At time 2, P1 arrives. However, P3 continues as its remaining time (3 ms) is shorter than P1's burst time (4 ms).
- At time 3, P0 arrives. Since P3's remaining time (2 ms) equals P0's burst time, P3 continues.
- After P3 finishes, P0, P1, and P2 execute sequentially based on their burst times.
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.
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 |
- P2 starts execution at time 0 and runs for 6 ms.
- Once P2 finishes, the next process (P3) executes, followed by P1 and P0, in the order of their arrival.
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. |