π§ What is Non-Preemptive Scheduling?
In Non-Preemptive Scheduling, once a process is given the CPU, it keeps it until it finishes or voluntarily gives it up (e.g., by waiting for I/O).
π The OS never interrupts a running process, even if a higher-priority process arrives.
π§© How It Works
Process P1 starts running β
P2 arrives (higher priority) β
P1 keeps running β
Only after P1 finishes, P2 gets CPU
Thereβs no forced context switch. The OS simply waits.
π°οΈ When Is the CPU Released?
-
The running process terminates
-
The process moves to waiting state (e.g., waiting for I/O)
β Advantages of Non-Preemptive Scheduling
| β Benefit | π Why It Matters |
|---|---|
| π§ Simple to implement | No need for complex interrupt handling |
| π Low overhead | Fewer context switches (less CPU time wasted) |
| πΎ Predictable | Good for batch systems and embedded environments |
| π Safer for shared resources | No risk of being preempted while holding a lock |
β Disadvantages
| β Issue | π Explanation |
|---|---|
| π Poor responsiveness | Slow for interactive or real-time systems |
| π§ CPU hogging | Long processes block shorter, urgent ones |
| β οΈ Starvation possible | Important tasks may be delayed indefinitely |
| π Low CPU utilization | If a process blocks on I/O, CPU may sit idle |
π Common Non-Preemptive Scheduling Algorithms
| Algorithm | How It Works |
|---|---|
| First-Come First-Served (FCFS) | Run processes in order of arrival |
| Shortest Job First (SJF) | Run the shortest total burst time process first |
| Priority Scheduling (Non-Preemptive) | Run the highest-priority ready process β but donβt preempt current one |
π§ Interview-Ready Definition:
Non-Preemptive Scheduling is a CPU scheduling approach where once a process starts executing, it runs to completion or until it voluntarily releases the CPU. Itβs simple and predictable, but less responsive β making it unsuitable for real-time or interactive systems.
π₯οΈ Real-World Analogy
Imagine a railway crossing where once a train starts crossing, it must finish completely before another is allowed β even if an ambulance is waiting.
Thatβs non-preemption.
π Summary Table: Preemptive vs Non-Preemptive
| Feature | Preemptive | Non-Preemptive |
|---|---|---|
| π§ Interruptible | β Yes | β No |
| π Response Time | β Fast | β Slow |
| π Context Switch Overhead | High | Low |
| βοΈ Fairness | Better | Can lead to starvation |
| π§° Use Case | Interactive/real-time | Batch/embedded systems |