Preemptive scheduling is a method used in computing to temporarily interrupt an executing task with the intention of resuming it at a later time). This interrupt is done by an external scheduler with no assistance or cooperation from the task. Preemptive scheduling involves the use of an interrupt mechanism that suspends the currently executing process and invokes a scheduler to determine which process should execute next). In preemptive scheduling, the operating system kernel can initiate a context switch to satisfy the scheduling policys priority constraint, thus preempting the active task). Preemptive scheduling is used to distinguish a multitasking operating system, which permits preemption of tasks, from a cooperative multitasking system wherein processes or tasks must be explicitly programmed to yield when they do not need system resources).
In contrast, non-preemptive scheduling is a method used when a process terminates or switches from running to the waiting state. In this scheduling, once the resources (CPU cycles) are allocated to a process, the process holds the CPU until it gets terminated or reaches a waiting state. The executing process in non-preemptive scheduling is not interrupted in the middle of execution and waits until its execution. Non-preemptive scheduling has minimal computational overhead and is very simple to understand and implement.
The main difference between preemptive and non-preemptive scheduling is that preemptive scheduling interrupts the currently executing process in the middle of execution when a higher priority one comes, whereas non-preemptive scheduling does not interrupt a process running CPU in the middle of execution. Preemptive scheduling is prioritized, and the highest priority process is a process that is currently utilized, while non-preemptive scheduling is rigid. Preemptive scheduling is very cost-effective because it ensures the integrity of shared data, while non-preemptive scheduling is not in the situation of non-preemptive.
In summary, preemptive scheduling is a method used to interrupt an executing task with the intention of resuming it at a later time, while non-preemptive scheduling is a method used when a process terminates or switches from running to the waiting state. The main difference between the two is that preemptive scheduling interrupts the currently executing process in the middle of execution when a higher priority one comes, whereas non-preemptive scheduling does not interrupt a process running CPU in the middle of execution.