difference between preemptive and nonpreemptive scheduling

pre-emptive and non-preemptive scheduling are two different ways in which scheduling can take place now remember that pre-emptive and non-preemptive scheduling is not CPU scheduling algorithms but they are two ways in which CPU scheduling takes place.

pre-emptive scheduling

CPU could be given to some other process so we call it a pre-emptive scheduling because before it has completed the CPU is taken away from it and even in point number three we see that it was in a waiting State and then it went to the ready state that means it was ready to be executed and keep in mind that this was already a running process which came to a waiting State then to the ready state here also we can give the CPU to some other process instead of giving it to this same process so we see that the CPU is taken away from it before its execution was completed so here also it is a pre-emptive scheduling so we see that in pre-emptive scheduling the basic idea is that the CPU can be taken away from a process even before it has completed its execution or even before it is going into a waiting State so that is what we mean by pre-emptive scheduling and in non pre-emptive scheduling the CPU will never be taken away from a process until and unless it has either completed its execution or it has gone to a waiting State so that is what we mean by non pre-emptive or cooperative scheduling so if we compare these two types of scheduling we will need these two types of scheduling for different scenarios we cannot say one is better than the other we may need both of them according to the different scenarios that we have and different operating systems follow different kind of scheduling it may be pre-emptive or non pre-emptive.

Non pre-emptive scheduling

non pre-emptive is a good way because a process will not be disturbed until and unless it is complete or until and unless it goes to a waiting State but there may be scenarios where when a process is being executed there is a very high priority process that has to be executed so at that time we may need to stop the execution of the current one and give the CPU to that process of higher priority so at that time pre-emptive scheduling will be required but also pre-emptive scheduling it comes with the course now why do I say that that is because there are different scenarios and one example that I will give is about shared memory so let’s say that there is a shared region of memory in two different process has access and different processes can write or read from that shared region of memory so let’s say that we are following this pre-emptive scheduling and one process was writing something into that shared region of memory so another process came and then the first process had to be preempted that means the first process was halted and then the CPU was given to the second process now the second process when it reads from that memory into which the first process was just a writing and did not complete what it was writing so that second process is going to read some inconsistent data because the first process that was doing the writing job did not complete what it was doing so those are some of the problems that we can face but as I said we cannot say that one is better than the other we may need both of these types of scheduling depending upon the situations.

Leave a Comment