Transcript for:
Understanding CPU Scheduling Fundamentals

In this lecture, we will be starting to study about CPU scheduling. CPU scheduling is a very important topic in operating system and it is a topic that you should really know about whether you are studying about operating system in general or if you are preparing for any exams of computer science in which operating system is a subject, then this is a topic from which you may get many questions. So, this is a really important topic and let us try to understand and see what is this CPU scheduling and what it does. CPU scheduling is the basis of multi-programmed operating systems. And by switching the CPU among processors, the operating system can make the computer more productive.

Multi-programmed operating systems, they work on the basis of the CPU scheduling. And why is that? And that is because by switching the CPU among processors, the operating system can make the computer more productive. Now you may be thinking, why did we say by switching the CPU among...

processes so this is the actual thing that is going to happen in CPU scheduling we are going to switch the CPU among different processes and thereby we are going to see how the productivity of our computer is going to improve so don't worry even if you don't understand what this means right now it will become clear when we go into the details of CPU scheduling so now let us see what are the important topics that we need to cover under this topic of CPU scheduling So, the first thing that we are going to do is to introduce CPU scheduling, which is the basis of multi-programmed operating system. So, I already told you that CPU scheduling is the basis for multi-programmed operating systems. So, we will introduce CPU scheduling and see what it actually means, what it actually does and how it makes our computer more productive. And secondly, we are going to describe the various CPU scheduling algorithms.

So, there are different ways in which CPU scheduling can be done. So, we will see the various algorithms that we have which helps in accomplishing CPU scheduling. And we will see how these algorithms differ from each other. And we will see which of these algorithms perform better in particular situations. So, these are the main topics that we are going to cover.

First of all, we will study what CPU scheduling is. Then we will look into the algorithms. So, these two topics are very important. And we will try to go into the details of these topics and we will try to make CPU scheduling very clear to all of us.

So, before we delve into the details of CPU scheduling, let's first get the basics right. Let us first try to understand in a very basic and in a very simple way what CPU scheduling means and then we will see what is the importance of CPU scheduling. And after getting the basics right and after trying to understand it in a simple way, We will go into the details in the coming lectures.

So, coming into the basics, let's talk a bit about single processor systems and multi-processor systems which we have already studied before in this lecture series. So, in a single processor system, only one process can run at a time. So, we know that in a single processor system, there is only one processor.

In that one processor, 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. But we already saw that we have multi processor systems as well. So, multi processor 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.

So, the objective of multi-programming is to have some process running at all times to maximize CPU utilization. So, we know that the objective of multi-programming is that we want some process to be running at all the times so that the CPU is always utilized by some process. So, a process is executed until it must wait, typically for the completion of some IO request. So, when a process is being executed, let's say that it is using the CPU, it is using the processor, the CPU and it is being executed and that process is in hold of the processor.

And what happens is that when that process needs some IO executions to be done, then what happens, it requests for the IO operations to be performed, that is input output operations to be performed. And until and unless that IO operation is not complete, It has to wait. So, while it is waiting, what happens is that it is still in 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. So, when a process is in hold of the processor and while its 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. So, with multi-programming, we try to use this time productively. And what do we mean by this time? This time is the time that we talked about here, which is the time that is wasted when the CPU is not doing any useful work. So, we want to make use of this time with multi-programming and make it productive.

So, let's see with the help of CPU scheduling, how are we going to be able to make this time productive. 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. So, 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.

So, 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, the CPU will be taken away from them and it will be given to some other process. process.

So that is what happens and in that way we see that we can make the computation more efficient because the CPU will not sit idle. It will always be utilized by some or the other process. 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 let's try to understand from the name itself CPU scheduling scheduling what do we mean by scheduling scheduling means we are trying to assign a particular time for doing a particular task so you may prepare your schedules your day-to-day schedule that at this time I will be doing this thing and at this time I will be doing this thing so you are preparing a time schedule for yourself so in the same way the operating system will prepare a schedule as of which process should get the CPU at what time or how long should they wait and things like that. So, this is the place where CPU scheduling comes into picture. So, we may think that what is the rule that CPU scheduling follows in order to accomplish this task.

So, there is not just one CPU scheduling rule but there are many rules. So, depending upon the situation we may use one of these rules. So, that is what I talked about the different algorithms of CPU scheduling that I said in the beginning of this lecture.

So, different algorithms will have different ways of assigning the CPU to different processors at different times. We will be studying those algorithms one by one and we will see how CPU scheduling happens in these different algorithms. So, with this I hope the very basics of CPU scheduling is clear to you and I hope you understood why we need CPU scheduling and from the next lecture onwards, we will be going into more details of CPU scheduling, trying to understand the terms and trying to understand the ways and also the different algorithms and we will see how CPU scheduling is done.

So, I hope this was clear to you. Thank you for watching and see you in the next one.