CPU scheduling is the basis of multiprogrammed operating systems and by switching the CPU among processors the operating system can make the computer more productive.
Multi-program operating systems work on the basis of CPU scheduling because by switching the CPU among processors the operating system can make the computer more productive.
CPU Scheduling in Various Processor
So coming into the basics let’s talk a bit about single processing systems and multiprocessor systems, in a single processor system only one single process can run at a time and any other processes must wait until the CPU is freed and can be rescheduled so when one process is running we have to wait until that process is completed and only after that any other process that is waiting can be given the CPU for its own execution so this is what happens in single-processor systems.
How Multiprocessor utilises CPU
We already saw that we have multiprocessor systems as well so multiprocessor systems were much better because there are more number of processors and hence there can be more number of processes running simultaneously at the same time. The objective of multiprogramming is to have some process running at all times to maximize CPU utilization.
So we know that the objective of multiprogramming is that we want some process to be running at all times so that the CPU is always utilized by some process.
CPU Scheduling – How does it work ?
A process is executed until it must wait typically for the completion of some I/O request so when a process is being executed that says that it is using the CPU it is using the processor the CPU it is being executed and that process is in the hold of the processor and what happens is that when that process needs some are your executions to be done then what happens it requests for the i/o operations to be performed that is input/output operations to be performed and until and unless an i/o operation is not complete it has to wait so while it is waiting what happens is that it is still in the hold of the processor but it is not using that processor because it is waiting for the i/o operation to be completed first so what happens is that in a simple computer system the CPU then just sits idle and all this waiting time is wasted and no useful work is accomplished.
When a process is in the hold of the processor and while execution was being done if that process needed some I/O request to be complete then it has to wait for that I/O request to be complete and while it is waiting for it to be complete it is still having that processor with it but it is just waiting and that processor is not being used at that time so the CPU is just sitting idle and then all the time that it is sitting idle that time is wasted because nobody is using the CPU at that time hence we see that there is going to be a decline in our productivity.
Because of this factor that we have seen here so the basic need for CPU scheduling is to avoid this, we don’t want the CPU to sit idle at any time so what we want is that if there are processes available then we want the CPU to be utilized as much as it can be we don’t want the CPU to sit idle so in order to accomplish this we are going to introduce CPU scheduling.
How multiprogramming uses CPU Scheduling
So with multi programming we try to use this time productively and what do we mean by this time – a time that is wasted when the CPU is not doing any useful work so we want to make use of this time with multiprogramming and make it productive so let’s see with the help of CPU scheduling so what we are going to do is that several processes are kept in memory at one time so instead of having just one process we will be having several processes kept in memory at one time and then what happens when one process has to wait the operating system takes the CPU away from that process and gives the CPU to another process and this pattern continues.
We saw that in the simple computer system when one process is waiting for some IO request to be complete then the CPU is not being utilized so what we are going to do is that when one process has to wait the operating system will take the CPU away from that process because that process is not using that CPU at that particular time and what will it do it will give that CPU to another process and then this pattern continues.
The processor or the CPU is taken away from that process that is waiting and it is given to another process that process can make use of the CPU at that time for its own execution and this pattern continues that means whenever somebody that is some process has to wait for the CPU will be taken away from them and it will be given to some other process so that we can make the computation more efficient because the CPU will not sit idle. It will always be utilized by some of the other processes when we are doing this thing. What happens is that how do we determine which process should get the CPU or which process should wait or after how long should a process be given a CPU, All these things are going to be done and explained by CPU scheduling.