Operating System | Process Scheduler | Preemptive and Non-Preemptive Scheduling - cook the code

Sunday, 31 December 2017

Operating System | Process Scheduler | Preemptive and Non-Preemptive Scheduling

Process Scheduling

To determining which process in the ready state should be moved to the running state is known as Process Scheduling.
The aim of the process scheduling system is to keep the CPU busy all the time and to deliver minimum response time for all programs. For achieving this, the scheduler must apply appropriate rules for swapping processes IN and OUT of CPU.

Schedulers fell into one of the two general categories :-


Preemptive Scheduling
Preemptive Scheduling means once a process started its execution, the currently running process can be paused for a short period of time to handle some other process of higher priority, it means we can preempt the control of CPU from one process to another if required.
A computer system implementing this supports multi-tasking as it gives the user impression that the user can work on multiple processes.
It is practical because if some process of higher priority is encountered then the current process can be paused to handle that process.
Examples:- SRTF, Priority, Round Robin, etc.
Non-Preemptive Scheduling
Non-Preemptive Scheduling means once a process starts its execution or the CPU is processing a specific process it cannot be halted or in other words we cannot preempt (take control) the CPU to some other process.
A computer system implementing this cannot support the execution of process in a multi task fashion. It executes all the processes in a sequential manner.
It is not practical as all processes are not of same priority and are not always known to the system in advance.
Examples:- FCFS, SJF, Priority, etc.
Difference between Preemptive and Non-Preemptive Scheduling in OS
cookthecode

Difference between Preemptive and Non-Preemptive Scheduling in OS

Preemptive SchedulingNon-Preemptive Scheduling
Processor can be preempted to execute a different process in the middle of execution of any current process.Once Processor starts to execute a process it must finish it before executing the other. It cannot be paused in middle.
CPU utilization is more compared to Non-Preemptive Scheduling.CPU utilization is less compared to Preemptive Scheduling.
Waiting time and Response time is less.Waiting time and Response time is more.
The preemptive scheduling is prioritized. The highest priority process should always be the process that is currently utilized.When a process enters the state of running, the state of that process is not deleted from the scheduler until it finishes its service time.
If a high priority process frequently arrives in the ready queue, low priority process may starve.If a process with long burst time is running CPU, then another process with less CPU burst time may starve.
Preemptive scheduling is flexible.Non-preemptive scheduling is rigid.
Ex:- SRTF, Priority, Round Robin, etc.Ex:- FCFS, SJF, Priority, etc.

Key Differences Between Preemptive and Non-Preemptive Scheduling

  1. The basic difference between preemptive and non-preemptive scheduling is that in preemptive scheduling the CPU is allocated to the processes for the limited time. While in Non-preemptive scheduling, the CPU is allocated to the process till it terminates or switches to waiting state.
  2. The executing process in preemptive scheduling is interrupted in the middle of execution whereas, the executing process in non-preemptive scheduling is not interrupted in the middle of execution.
  3. Preemptive Scheduling has the overhead of switching the process from ready state to running state, vise-verse, and maintaining the ready queue. On the other hands, non-preemptive scheduling has no overhead of switching the process from running state to ready state.
  4. In preemptive scheduling, if a process with high priority frequently arrives in the ready queue then the process with low priority have to wait for a long, and it may have to starve. On the other hands, in the non-preemptive scheduling, if CPU is allocated to the process with larger burst time then the processes with small burst time may have to starve.
  5. Preemptive scheduling is quite flexible because the critical processes are allowed to access CPU as they arrive into the ready queue, no matter what process is executing currently. Non-preemptive scheduling is rigid as even if a critical process enters the ready queue the process running CPU is not disturbed.
  6. The Preemptive Scheduling is cost associative as it has to maintain the integrity of shared data which is not the case with Non-preemptive Scheduling.

No comments:

Post a Comment