Difference Between Preemptive and Nonpreemptive Scheduling

CPU Scheduling

CPU scheduling is a process which allows one process to use CPU while another to hold on waiting-state due non-availability of resources. This process makes the full use of CPU resulting in a fast and efficient system.

As soon as the CPU becomes idle, the CPU scheduler in operating system select the process in the ready queue and allocate the CPU for execution of the process.

difference between preemptive and non-preemptive scheduling

CPU scheduling decisions are taken when following four situations occur.

  1. When a process switches from running-state to waiting-state (for example,
    an I/O request is being completed).
  2. When a process switches from the running state to ready state (for example
    when an interrupt occurs).
  3. When a process switches from waiting-state to ready state (for example,
    completion of I/O)
  4. When the process terminates.

During situations mentioned at point No.1 and 4, there is no choice in terms of scheduling; a new process must be selected for execution. However, there is a choice of scheduling in case of point No.2 and 3. When scheduling takes place only under 1 and 4, we say, scheduling is non-preemptive; otherwise the scheduling scheme is preemptive. Under non-preemptive scheduling, once the CPU has been allocated to a process the process keeps the CPU until either it switches to the waiting state, finishes its CPU burst, or terminates. This scheduling method does not require any special hardware needed for preemptive scheduling.

What is preemptive scheduling?

In the preemptive schedule, the processes with higher priorities are executed first. It is necessary to run a certain task that has a higher priority before another task although it is running.

If there comes a process with higher priority than the running process, the running process is interrupted for some time and resumed later when the priority process has finished its execution.

Starvation can occur to processes with lower priorities if processes with higher priorities frequently arrive in ready queue.

What is non-preemptive scheduling?

In non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state.

It is the only method that can be used on certain hardware platforms because It does not require the special hardware(for example, a timer) that is needed for preemptive scheduling.

In non-preemptive scheduling starvation can also occur if the process running has long burst time then the process with lower burst time will starve.

Difference Between Preemptive and Non preemptive Scheduling

  • The preemptive scheduling can be preempted that is process can be scheduled while in non-preemptive scheduling process cannot be scheduled.
  • Preemptive scheduling flexible while non-preemptive scheduling is rigid.
  • The preemptive scheduling is only possible on hardware that supports a timer interrupt while timer is not required in case of non preemptive scheduling.
  • Preemptive algorithms are driven by prioritized computation while non preemptive algorithms are designed in such a way that once a process enters in a running state, it is not interrupted until it completes its execution.
  • In preemptive scheduling, if a process with higher priority enters in a ready queue, the process with lower priority is removed while in non preemptive scheduling once the process allocated to CPU, it will complete its execution.
  • Windows used non preemptive scheduling up to Windows 3.x and used preemptive scheduling from Windows-95. Mac used non preemptive scheduling prior to OSx and preemptive scheduling since then.
  • Preemptive scheduling can cause a problem when two processes share data because one may be interrupted in the middle of updating shared data structures.
  • Preemption can also be a problem if the kernel is busy implementing a system call when the preemption occurs.

nc