Basics of computer science | Vignesh Sekar | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Basics of computer science

teacher avatar Vignesh Sekar

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

16 Lessons (2h 18m)
    • 1. How a computer works

      11:05
    • 2. How various parts of computer work together

      6:55
    • 3. Need for Operating Systems from scratch

      8:34
    • 4. How Input and Output devices work together

      4:18
    • 5. Program vs Process, States of a process

      9:23
    • 6. Degree of Multiprogramming

      5:29
    • 7. Types of Operating Systems

      11:54
    • 8. An Important point to note

      1:31
    • 9. Process Control block

      8:15
    • 10. Attributes of a process

      14:13
    • 11. Types of scheduler, Context switching

      11:23
    • 12. Various times of a process

      11:28
    • 13. Types of Scheduling Algorithms

      8:37
    • 14. SJF Scheduling Algorithm

      9:21
    • 15. SJF Example 1

      9:18
    • 16. SJF Example 2

      5:57
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

868

Students

--

Project

About This Class

Mastering the concepts of Operating Systems is very important to get started with Computer Science because Operating Systems is the program which is responsible for the ease with which we are able to use computers today.
In this course ,every concept of Operating Systems is taught in an easy-to-understand manner such that anybody without any prerequisites will be able to master the concepts in the easiest way.

Come and join me, I assure you that you will have the best learning experience of not just Operating Systems but also the core of Computer Science in a different dimension.

Meet Your Teacher

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. How a computer works : before seeing what an operating system says. Let first see what is when a computer system. Okay, see it? Computer system is nothing were It is a combination off Harvin software on data which are used to solve the problem of human beings. Okay. See, as a user, be wanted to Salo problems. Okay. For example, I wanted the access of a page. It's a problem. I wanted to end it. May photograph. It's a problem. OK, all these are problems of human beings. Now, in order to solve these problems, we use a computer system. Okay, We use that. Right? But you're saying we use a computer system. I mean, be used hardware devices, Some hardware do aces. Some software's south first have nothing but programs. Okay. Software and programs both mean one and the same on data. Okay. For example, let us assume I Maybe I wanted to aided my photograph. OK, which is a problem. A leading your photograph is a problem. No, to solve this problem, be used hardware harder means we use hardware. The personal computer, right? See, by hardware, I mean, we have CPU. Okay? See, the most important part our in our computer central processing unit RCP. Okay, it is nothing but a small chip. Okay? He is a cheap Know what the people do is it will fetch the programs. Okay. Programming software. You know, they're okay. The program, The programs will be stored inside the ram. Our memory know what the CPI will do is it will fetch the program from the memory, and then we will execute it. Okay. Any operation you do in your computer is being done by with the help off CP. OK, anything you do see paintings to execute on instruction for it. See, instruction is nothing but a part of a program. Okay, You can think off it like a line off a program. The collection off instructions are also called a sell program. Fine. No. The main, the main functional here for computer system is nothing but execution by the CPU central processing unit. Now, that is that is one important hardware. The ways we use in our computer, the second most important ways is nothing but a memory. Okay, memory. See, we have various levels off memory in our computer. Okay? We have bites by simply saying memory actually mean ram random access memory. But apart from that, there are various types of memory. One important part is, as I said, it is Haram. Okay, The second most important memory system is hardest. We also used other memory systems like cash registers on all of this. Okay, see, computers work on the basis off stored program concept. Okay. What does it mean? It in order to solve the problem of human beings, we write programs. Okay. Now, what did we use? We store the program in, say the memory. Okay, we will store the program inside the memory. Now, what will happen is this CPU central processing unit. The chip will end the program line by line our instruction by instruction. And then it'll executive OK, that this how the problem of human beings are solved today. See any soft? Very. We used today another computer. It has a program at the back end. Okay. For example, if you're using it, must it must work. No. Microsoft should have return. A program for Emmitsburg on that program will be stole inside your heart. Best Okay on. Do you fought for execution? The program will be moved from hard. This too. Damn on what will happen is CPU will fetch the program line by line. But focal program written. William Esport, right, Microsoft. That program will be first with the CPU line by line, and it will executed as a result off which were ableto use the software as we were using today. Okay. See, why are we actually doing the program from hardest ceramist? Different. That's that estimate is an important point which is discussed in the next video. Okay, which will be discussed in the next video. Fine. No, As off. No. Understand that any program with CP wants to execute has to be percent inside their AM. Okay, random access memory. We have a hard disk. Okay? It is an important bite. Now in a brawl, the program will be moved into the ram, and this is our CPU. What the CPI will do is it will fetch the program. Let us assume this is your password. Okay. This is a program on this program will be stored inside the ram on one of the CPI Will do is it will fetch the program line by line and then it will execute it as a result, Up with very able to use the software as we were using. Pretty OK, fine. Nadia, Jesse must when you take any software, whether it be Google Room, whether it before to shop any soft, very date, there should be a program which would be running at the back. And okay, program is also called. It's the software. No, no central processing unit will actually take the program right in line by line of genital executed. So fine. So the most important thing, which will be present instead of Grammys program. Now, apart from program, that will be something called blessed Data. Okay, they think don't data. Our software is useless rate without data. What do you want to use the software, for example, if you're anything afford everyday, If you're using photo shop, which is a software you need some photographs to Idiot. Okay, Those $4. They say that as data Day dies in nothing but any information, any raw data, for example, you take you may just video for a lawyer friend explained we need Then you take all this basically say that doesn't data. OK, now, a combination off a combination of hardware software on data are actually used in our epistle the problem off human beings. Okay, this is what our computer system is actually doing. Any problem use? Want the salt in? Ignore computers. We actually write programs. Okay, fine. Now, one question, you might ask is why you are using these many levels off memory. Okay, rather than using one Lee one member, one memory system, we're using Karam hard this cash register. See, Actually, all of them are bring only one thing there. Nothing that they are. Actually, either storing program our data within them. Right. So? So that's CPU can fix them and then executed. That's what we're doing it. No. One question you might ask is where Using these many levels of memory, the reason is very simple. OK, they were using these many levels of memory because every memory system has its own. Our front pages as well. Is that the state party? Okay. See, coming toe cash on registers. You can You can see it a bit later. I don't think about it too much because this is actually covered in case of computer organization and architecture. Okay, this is not very important. Coming toe operating the stumps. You know that one different operating systems. These two memory systems, if you'd be really comfortable it okay? Know what this around would be different. So did Graham. And hard disk is very simple. OK, whatever is stored in hard disk is actually permanent. Okay, The data, which is tour in hard disk, his permanent. Which means in case if you store some data inside the hard disk, the data will remain permanent. Okay, but that is not the case coming to ramp the data with you store Ingraham. It doesn't guarantee that it doesn't mean that the date I sexually permanent once the other gets off. Okay, You know you're using a computer, and in case of the date ice inside the ram in case in the power goes off on your computer guard disconnect er from the current, you know what will happen is the data will get lost. Okay, That is the disadvantage with Graham. And that Is that bonded with hard disk. Okay, fine. No, but that is one. That is an advantage with Ram comparing the hardest. The thing is accessing either a program. Our data from Ram is actually very, very, very fast comparing toe hard disk, which means that access time off Ram is a 1,000,000 times faster than that of heart. This. Okay, see, none of the access. An instruction from the hard disk. You don't take a lot off. Okay, within that during that time, you could have access to 1,000,000 instructions through the ramp. Okay, so I can say that a ram is 1,000,000 times faster than that of heart. This actually does 1,000,000 is not an exact number. It really varies. Based on implementation, for example, there's a different different on the size of the ram. Right size off the ram actually decides their speed. The war for bigger the time you have, the more faster your computer will be. OK, why? You will understand it once you get into multi programming concept. Okay, we have in this course once you get into multi program and you'll understand why increasing the size of the ramp is actually increasing the speed of four computer. Okay, I think so. That wanted with hard disk is data that you stories permanent that vented to Durant. Miss Access time is very, very fast. So no V as a user want at the boldizsar Spontaneous. OK, we don't want We don't want both decide what it is that this finding innovative told it with it to some extent. But what we want this one both these advantages. One thing is over. Data should be permanent. The second point is, we need access the data in a very far, very fastly. Okay, so what we do is we have both these memory systems one, Mr Graham. And this is hard disk. No, every any data, which is immediate. Okay. Any data, you take another computer, Definitely present in, say the hardest. OK, so either it is a program. Our visit, our visa data or whatever it is will be present in say the hardest. Now that because problem is the time taken by the CPU taxes the state, I will take very list very long time. Right? That is that is one that they said went with hardness. No, no. What? That doesn't want age. What we do is we actually move this data inside the ram, okay? So that all the CPU can access the data. Very fastly. Okay, so we got bored advantages. Okay, We got bored. The advantages. One advantage is that the data which were storing his permanency. Actually, one important point you need to know. Curious The data is actually copy and paste it into the ramp. Okay. Does not cut paste. It is like car copy paste. OK, which we do in our computers. Which means if this thing has this has to be more in save the damn. A copy of this will be created and it would be moved into the ram. OK, which means this will be present. Both Ingraham as well as in hard disk. Why? Because in case in the data gets lost inside the ram, you distill percent inside the hardest. Great. We want permanent data. Fine. So we're going able to get both the advantages. One thing is very able to access the data. Our program very fastly Truth era as well, less. We are able tohave or data permanently in, say, the hard disk. So both these problems have been solved by using boda boredom and many systems OK were able to get both the advantages by using both this memory systems. So this is the reason use various levels of my medicine stops. Okay, cash register are a bit make more complex. Actually, you don't need to understand it very clearly. Understand this This subject off operating systems, okay? It is mainly covered in computer organization architecture. Okay, fine. 2. How various parts of computer work together : finally see, this seems so far. We have seen what? This may be A computer system. Right? Fine. Let this is, Um this is over computer system and it is having CPU ram on the hardest. No. Any problem? You A In our computer, it would be definitely be present in, say the hardest, right? It would be definitely presenting. Say the hardest. Let this issue. We have a high level program, right? We have a high level program. See, high level programming is the programs which be right. For example, See program are Java program. Are there any software be used like photo shop? Are Google chrome or water? We say the most high level program, right? No, this high level program cannot be directly placing. Said the hardest, right? We cannot place it. The reason being saying, Why do we write the programs? We write programs because those programs has to be executed by the CPU at some point in time, right? RCP and fetch the program and then it'll executed. That is the reason, very programs. No, the problem here is our CP will not be able to investor high level program right, which means the programs written using CEO job are by turn or whatever. Okay, Such programs cannot be understood way, CPU or CPU cannot. Best time one lee once and zeros trade can only and listen by any numbers which is once and zeros. So what we do is be convert other source program into something called best machine court Machine code is nothing but once and zero side. The other complete program which you write will be converted in p. A core on this court will have only once and zeros right. This is what we mean by mission Court. We can also say that docking XY quarter executable court are even lower level program. I deserve the various nine names be used in order to refer machine court. Fine. So any program you take will be converted into mission court by using a program called Best compiler. Right? Compel. It is also a program software which will convert a high level program in their mission court. Now, once we have converted this walking Louise, you place the machine court into the hard disk of the computer, right? That's what I told that any program you take will be presenting said the hardest And most importantly, that program will be in by in machine code that the program will be in machine code. Fine. So we have a place in the program and say the hardest. Don't tell me how CPU will actually access a program, right? It see any program? Be right. It has to be executed by the CPU at some point in time. Now hold CPI will execute the program. The most important point here. You know, the scares our seeping. You cannot access the hardest, directly, right over. See if you will never be able to access the hardest Directly oversee puke. Where can only access the ram directly. Right? This can always happen, but they should never happen. So what we do is let us assume our CPUs requesting for a program safety One excuse requesting for a program people know what we will do is we will search for program be one inside the ram. I will search for the programming superior in Sitaram. See one more important point you can even see in the Bagram. Their size off ram is very small compared to size of the hard disk writes a self from it's very small compared to size of heart. This even if you take place computer the rams between something around four gigabytes at Max it can be somewhere around 16 gigabytes. Right? This is the size of the used create for right. But if you take hard is it is something around 500 Gp are even to people these days, right? The size of hardness is very, very large compared to size off from the reason being hard this case very cheap, right? There s Ram is very, very costly. So this is the reason the science off harvest is very large comparative myself from in today's computers. Fine. So one thing is for sure, we cannot place all the program since it right, we cannot place all the programs. Why? Because the size of hard disk is very large. We feel how the hardest full of programs, How can you place all the programs and say that it is not possible? Right. So since size of the Ram is very small, we cannot place all the programs in, say, the ramp. Fine. Let's come back to this. So once. If cp wants to execute preprogrammed p one, it will search in the Ram engaged. The program is present in the run. It is fine. It will fetch the program from the ramp. In cases pureness present inside the Ram CPU fits the program. Be one had genital executed. Okay, we'll put Fetch it line by line and then it'll executive. It is simply it's very, very less time. Why? Because here are CPU. Is one Lee accessing the ram right. In order to fix the program the one that has in cases the program gets it. P one is not present in the Ram CCP searching for program P one right now. In case if P one is not present in the ramp In that case, one thing is for sure be one will be definitely presenting the artist right now. What we will do is May will copy the program, be one and then we will place it in the rack. Right? For example, we wouldn't be present in save the damn inside. The hardest now watching do is if p one is not present in the Ram, we will create a copy off p one and then we'll place be one in ST around right now. Once this has been more into the RAB. C p will take the program from their AM right. This is how our program is generally access by ever CPU engages, The program is present in the ramp. Cp radically access it. In that case, it takes very less time because it involves only Ram access time. Right? We need to access one leader on. We know the Karam is very, very fast. Fine, Let us in cases. The program is not presenting the Ram. In that case, we need to access both hard disk as Lillestrom Way because we need to take a copy. The program people from the hardest. So we're accessing the artist on. Once in place, the program in Syndrome RCP will read the program from the ramp right So effectively we're accessing both the hardest as well. Lest Ram, why didn't the northern hard disk is very, very slow? He takes a lot off them in order to access the hardest. So in case if the seat in the program CPUs act asking for is present in the ramp, it is going to take very less time for the CPU to access the programme whereas engaging the program is not present in the ramp. It is going to take a lot of time for the CPU to access the program because we need to access both the hard disk as well. Let's ramp on. We know that hard biscuits Very, very slope. Fine cities are important points. Ahram is costly than hardest, right? This is the reason we have the science off from Toby. Smaller than hardest. Also, your am is very, very fast comparing hardness fine. 3. Need for Operating Systems from scratch: Well, so far we have seen that the size of the hard disc will be much bigger than the size of the ramp. Ok? Now let us assume that just for an assumption, our hard disk can hold 500 programs, ok? Similarly, let's assume that our RAM can hold 15 programs. Why? Because size of a Rama's will generally be with lesser than the size of the hard disk. Fine. Now, out of this 500 programs which, which are present inside the hard disk, 50 programs should be copied from the hard disk and then mode into the RAM. Ok. It is copied ladies, just like copy paste. Ok, it is not like that paste, which we do in computer. Okay? This 50 programs which I am moving into the RAM, should also be present in say Dar desk. Okay. Such a way I copy the 50 programs and place it in the ramp. Now my question is, out of this 500 programs, which 50 programs should be copied from the hard disk into the RAM? That is the question, okay, see further. What we can do is the best idea is we can move the 50 programs, which the CPU is most likely to request next, right? Why? Because if the CPU is requesting for a program which is present inside the RAM, it takes very less time for the CPU to access it. But in case if the program which CP is trying to access in the RAM is not present, when in case the CPU is trying to access a program which is not present in the RAM. It is going to take lot of time because we need to copy from the hard disk and then placed it in the RAM and then we might have to take it from there RAM. It is going to take lot of time. So we should pray to move the 50 programs which the CPU can request next from hard disk to memory. Okay? But the problem here is we will never be able to say which program will the CPU be requesting next. Okay, why? Because whatever CPU can request is highly variable. We can't really predict. For example, as a user, I can actually, I can actually open any software as I like, right? Nobody can say it is that I will open us after one lead is because it is a future. Similarly, our CPU cannot predict. Our CPU can ever, LCP can actually request for any program, okay? There is no, nothing like our CPU should request this program. So this is a future and it is not possible for anyone to, anyone to actually derive it exactly. So one thing we can do is we can do prediction or we can go for, I guess, okay, we can simply say that we can simply put some program from hard disk to memory, some 50 programs based on some algorithm or some idea. Okay, see why do we need an algorithm for this? See what I can do. For example, there are two teams which are playing a match, okay? Email and DB. Now, they are going to play the match tomorrow and you want to predict the winner, okay? Now you can predict the winner based on various algorithms. For example, you can take the past history and see which team has won the most number of matches and say that he will be the winner tomorrow. Okay. You would guess might be correct or might not be correct. Money you'll know it when you tomorrow. Similarly, we can go with another team which has lost most number of times. But still you can say that that Amy's playing in a ground which he does one all the matches so far. So you can say that the team beak and win the match. Okay, so there are various kinds of algorithms. So you can come up with, you can come up with a lot of algorithms saying that this can be hand, this can happen, that can happen, okay? So this is just a guess. So similarly here also we can recreate any 50 pro equity can move. You need 50 programs from hard disk to memory based on various ideas saying that the program which is smallest in size, maybe referred by the CPU in the future. It is just an idea ok, need not be correctly. Similarly, the 50 programs which are the biggest insights, can be referred by the CPU next. And so I need to move the 50 programs, which are, which is the biggest insights from hard disk to memory. So I can go for various kinds of guesses. So this guessing is done by something called as operating systems. Okay? Other operating systems is a program. It is a huge, Is a big program. It will have lot of functions inside it, okay? Now, one of the functions inside the operating systems will hold the logic or algorithm, which will say that, bitch, I'm in case he feet come across a situation such that more than one program is trying to access the, capture the RAM here, more than one program wants to cram, right? But we can move on only a few program into the RAM. Now, which few programs we should move from hard disk to wrap. That decision is being done, being taken care by one of the functions of operating systems. Similarly, that might arise a situation where let us assume there are more than one program in the RAM. Let us assume there are two programs in the RAM which are trying to access the CPU at the same time. It is still definitely possible. Why? Because I might actually open more than one program in my computer. In that case, what will happen? Both the programs has to be, has to be executed by the CPU. Now, it's up to the CPU to decide which program should it execute next. Actually, CPU will not decide. Cpu doesn't know anything other than executing the program. Now it's up to us to decide which program should the CPU execute next, right, among the two programs which are trying to access the CPU. Note, again, for that we write another function inside of our operating system which will decide which among these two processes should capture the CPU. Okay? So what is actually happening here is it is nothing but results allocation. See what is meant by resource. Anything which is present inside of a computer is nothing but a resource. For example, CPR is a resource, RAM is a resource. Hard disk is a resource. Mouse, keyboard, anything printed or any device you can take in our computer. We can say that as a resource, okay? Now, in what's happening here is more than one program is trying to access the CPU and it's up to your operating in AI needs. That operating system is deciding which among these two programs should access the CPU using its program C operating systems, it's a program. Now, among this, there are various functions, and each function is having a logic. This function is having a logic saying that which among these two programs should access the CPU. Similarly, even here we are, we have already seen that whenever two programs are trying to access the RAM, the operating system is deciding which program should should get hold of the ramp, which means which program should be moved from hard disk to memory. Again, this is being decided by our operating systems. What operating systems is generally doing is it is taking care of something called as the resource allocation. Which means if more than one program is trying to access a resource. Now operating system might have to say which one should get hold of the resource first, see, of course, every program Bill. Every program will definitely get hold of the resource at some point in time. That's for sure. Now, among them, which ones should capture the resource first, that is all cushioned and that is being answered by other operating systems. Okay, fine. So the important point which you might have to note here is operating system is nothing but a program which acts as a resource allocator are a resource manager. Okay. That is only point which for this, that is what I wanted to explain. So I went for a lot of explanations just to give a rough idea of what is happening with the computer. So in case if you're not able to understand these points, it is still fine, right? To get a rough idea about it because we are going to see all these concepts in a much more detailed way. Okay? This is just a rough idea, okay? Nothing, nothing that you should be able to understand it exactly. So tried to get a rough idea about these points. We are going to see all these points in a very detailed way with a lot of problem solving, lots of problems, okay? You'll get it very clearly. So fine. 4. How Input and Output devices work together: So one sub program has been moved from hard disk to RAM. What are all the things this program can undergo? Either this program will be in the run, this program will be in the RAM, and it will be executed by the CPU by taking line-by-line. Such things be say that test execution, execution or this program which is in RAM. And we've got ival, okay, such thing we say that is I o event. Another possibility is that this program is neither performing. Execution, is that this program is neither executed. Now, this program is waiting for IO event. In that case, this program is actually waiting for the CPU to execute R. It is waiting for some IO event, right? In that case, we say that this program is actually waiting for some event to happen. Ok? So in simple terms, I can say that c 1 I want to tell is there is something called as turnaround time. Okay. They're not Dongdaemun caldo. First, let me write the formula and then I will explain it. Okay? Donor on diamond caldo, waiting times plus burst time plus IO time. Okay? So every program at some point in time will be loaded into the RAM, ok, let us assume that, that is a program named as P1, okay? This program is low. Let us assume this program has been loaded from hard disk into RAM at 01:00 AM. Okay? I see 01:00 AM. And let us assume that this program has completed execution at 03:00 AM, okay? This program has completed execution at three AM. And I already told you that once the program has completed its execution, the program will be completely removed from the RAM. Ok, this program will be completely removed from the RAM. Now this duration of time from 10am to three AM is also coordinates turnaround time. Ok. Now during this turnaround time, what are the things this program should have undergone? Which means during this time from one name to 3AM, this program should have either beta, which means it, you'd have waited for some event to happen. This program should have been executed by the CPU of C execution and execution time and burst time, both are same. Okay? We can also say this execution time as Burstein both are same, okay? Are this other program should have undergone Ivo. Ok, so this turnaround time is a combination of waiting ten plus burst m plus m c. Actually, we can't say which one among waiting or burst are I0 will happen. In which order? Okay, in which order this will happen. A program, once it is loaded from hard disk to Ram, it can undergo either weighting them for some duration of time or it should have been executed for some duration of time. Are this program should have been undergoing IO for some duration of time. In what order this happens is really independent on the program. For some programs, it, for some programs the order ordering will be the ordering will be different from one program to another. Okay, that's what I wanted to tell you. See in case if you didn't understand this formula, you don't really worry because we're going to z, lot of problems come into this concept. Okay? We're going to see something called a scheduling algorithm. So okay, that we will be seeing all this concept. Okay, fine. 5. Program vs Process, States of a process: So now let's see the difference between a program and a process. Ok. See, we already know that any program in our computer will be converted into machine code, also called as LaTeX EE core, and then it will be placed inside the hard disk. Ok, we have seen it already. Now let us assume that Google Chrome and MS Word are two softwares which are present in a computer, which means inside of a hard disk in theta will computers hard disk in Google Chrome dot EXE and Emma's words.txt. These are the two executable files which are present in our hardest, fine. Now. Now, now coming to this, now this is called as a program. Ok. This is, this is nothing but a software or a program. Now what do you, what do we actually mean by your processes? See bendable, I click us or let us assume I have opened my computer. I have logged into my computer, and I have double-click the Google Chrome icon, which means I have opened the Google chrome software. Okay, now what our CPU will do is it will check that Google Chrome's program. So our search, the Google Chrome's program in our ramp. Ok. Now let us assume the program is not available inside the RAM. So as a result of which, what will happen is this program might have to be moved from hard disk into RAM. Ok, this program made have been moved into from hard disk can be run. We already seen this. Now what will actually happen is since I have, I have clicked the Google Chrome icon, which means I have opened the Google chrome software. A new copy of this Google Chrome will be created. This program, okay? A new copy of this program will be created in the hard disk itself. Okay? This program is called as a process. Okay? C program is nothing but anything that you type. For example, the company Google has developed software through a program. That is what we mean by a program, then that is available as indoor dxi parliament in our hard disk. Now, whenever this program has been executed, are this program has been opened by my computer, a new copy of this program will be created. And this is what we mean by a process. C, B can open Google Chrome in multiple tabs, right? For example, I can use open, open link in new window. I can, I can open to Google Chrome Windows at the same time right? Now what will happen is for this program, though, instances of Google grown program will be created inside the hard disk. Ok. This is nothing but program peres. These two are processes which are created for this program. Okay? So for a single program, multiple processes can be created. Okay? Finally, now what will happen? These two programs will be moved into the RAM, and then it will, it will, it will execute, it will undergo eyeball this, we have seen it OK, it looks like a normal program. This will also undergo all these things. Fine. Now for any program, we have seen so far, it undergoes through various stages, right? Initially it started as a source program, then it has been converted into machine code. Now the mesh, then the machine code has been placed inside the hard disk. And then he tells me more into the ramp. Now once it does, we moved into the RAM into it can undergo either i, o, R, it can be, it can, it can be executed by the CPU. Are it can, it can simply remain in the RAM waiting for some event to happen, are waiting for some, waiting for a execute, executed by the CPU or waiting for IO. Okay? That is what we have seen so far. So during this entire journey. Yet Program undergo a program or a process undergoes various stages. See, actually, there is no much difference between a program and a process, though is said this explanation. In most of the textbooks, they use program and process interchangeably. Okay, it is fine, but still, it is good to know this actually, ok, what is the difference between program and process? Now? Fine. Now, this program and this process undergoes various stages, right? Various states. Now we say each node we have named each, each of these states using, using these things. Okay? For example, whenever we click the Software, for example, whenever we open the Google chrome software, this program, this program has actually created this process, right? This program has actually created this process. Now we say that this process is a new state. Okay? This process is in new state because this process is being newly created. Fine. Now at some pointing, Damn this program, this process will actually be moved into the RAM, right? Because CBO can actually access one leads directly from the RAM and not from the hard disk. So at some point in time, this process has to be moved into the RAM and be say, let us assume it is this process Google Chrome is now present inside the ramp, is present inside that ammo. Now within the RAM, we have already seen that any program or process can either be executed by the CPU. Because I can either be executable and CPU are it can undergo I0, R. It can be in the RAM waiting for some events. Right? Now in case if the program is within the RAM and it is neither performing Iwill, nor it is being executed by the CPU. But this process is waiting for some event to happen. In that case, we can say that this process isn't ready state, okay? Which means this process is actually ready for execution, are for IO. Okay? This process is actually waiting either per CPU are for performing I0. So we say that this process has in ready state. So, so far we have seen two states. Whenever the program process is being created inside the hard disk, we said that the process is in new state and whenever the process has been moved into the RAM. But it is neither performing Ivo, nor it is performing execution, execution by the CPU. We said that the process isn't ready state, fine. Now let us incase if the process is being executed by the CPU, taking line by line, we say that the process isn't running state, which means the process is being run by the CPU, are being executed by the CPC or running and executing both are same, right? So we say that the process is it running state. Now in case there is a small mistake here, actually. Ok. Here, here there is a small mistake, ok, it is not blocked state. It is actually I will state. I will state. Okay? So in case if the process is in RAM and it is performing some IO event, you know what an IPO means, right? Either reading or writing from IO devices is what we say there does i u. So in case if the process is in, undergoing Aibo, then we say that the process is in, I will state, okay, fine. This is also called as a blocked state. Okay? So why do we say this Ivo status block state is we, we will see this, okay, we move one when we are seeing actually scheduling algorithms, we'll see what why we say a process in Iwo status blocked state, ok, we'll see that a bit later. Now. We know that once a process has actually completed its execution, which means it's, it's completely done with everything. It would be completely removed from the ramp right? Now, once the process has completed its execution, then we say that the process is in terminated state. Again, once the process reaches terminated state, we will remove the process from the RAM completely. Fine. Now, there are two more states called us suspend release date and suspend Vt state. Now, in case if I say this and explain this, explain this, you will not be able to clearly understand it. So what I will do is let me take a water processes. I, let me discuss some more concepts about process. And then we will see these two things, okay? Such punter anti-state and suspend, wait state. Fine. 6. Degree of Multiprogramming: Now let's see what does one by degree of multiprogramming. Degree of multiprogramming. Degree of multiprogramming means maximum number of processes which can be placed in the RAM in our computer. That's what we mean by the degree of multiprogramming. Write C, this B. However ramp, let us assume our RAM can have at max three processes, which means C, our RAM is having some capacity, okay? Endeavor RAM is having some capacity. Let us assume three GB or 4GB or whatever it is, OK. Now within this space, that can be only a finite number of processes can be placed, right? For example, let us assume that psi is outward Ramis 4GB. Ok? Now, let us assume size of a single process equal to, let us assume four KB. Okay? And let us assume that it need not be always true. But just for this example, let us assume that all processes will have that same size, okay? That is assumption. Please make a note of it. It need not be true always. But let us, for this example, let us assume that size of every process is same, okay? Now the number of max, then the number, maximum number of processes which can be placed in our RAM is nothing but size of RAM divided by the size of a single process, which is nothing but size I-frame is four GB, which I can write it as two power 32 bytes divided by size of a single processes and I think but four KB we take and write it as Cooper to L bytes. Okay? So totally I can have bytes and bits will get cancelled. So I will be having, i can have at most two power 20 processes in say my RAM. So what I can say is the degree of multiprogramming in our computer is two power 20. I can have at max two-port at my, at max two port 20 processes in my Abram. Okay, this is what I mean by degree of multiprogramming. Now you might get a doubt what is meant by GB KB. How did I calculate this and all this again. So for that, let's see what, let's see about what is meant by GB. Okay, C, one K, b equal to two power ten bytes. And one MB is equal to two power 20 bytes. One GB equal to 2.30 bytes, one db equal to two per 40 bytes, and one byte is eight bits. Now this four, in order to calculate this, I can convert this 4GB into bytes, okay? It will make it much more easier. For example, for DBA can write it as 11 GB equal to two power 30 bytes. So four into two per 30 bytes, right? This four, I can write it as 2pi over two into two power 30 bytes. Okay? Now this, I can write it as two power 32 bytes. This is how I got this two port 32 bytes, okay? Similarly, this four KB, I can write it as one KB is equal to two power ten bytes again. So I can write as four into two per ten bytes, C, four KB. I am writing it as four into two power ten bytes, because one KB is equal to two Bore ten bytes, okay? One KB is equal to two power ten bytes. Now this can be written as, this four can be written as two squared. And so two square into two power ten, which is nothing but two power 12 bytes, right? This is nothing. This is what I have Galba IO written as TOPO. This way I have written does to port 12 bytes, right? Two-port 32 dividend a two-port oil is nothing but two power 20. Okay, see, let's see about this. Kb, MB, GB and all this a bit later. Okay, we will be discussing a lot of problems, but we see about memory management, okay? Now just to adjust to actually explain the concept of degree of multiprogramming, I have taken the small problem, ok? Degree of multiprogramming is nothing but maximum number of processes which can be present in the RAM for computer, fine. 7. Types of Operating Systems: Fine. Now let us see what are, what are the various types of operating systems we have, OK. Well, one thing is nothing but batch operating system. Batch operating system is actually not used today. It is being used long back, okay? Batch operating system means in the degree of multiprogramming is always one. Okay, that is the batch operating system. It will be always having the degree of multiprogramming s1, which means at max, that can be one, only one process which can be present inside the RAM. What, what do we mean by that? C, D, B, actually placing a process from hard disk into RAM, right? And then CB will execute it. Now, what we will be usually doing is whatever we have seen so far, what we'll be doing is we'll be having more than one processes in save that app, right? I have not explained it actually till now. Let me explain it now. Usually what we will be having is we will be having more than one process as for example, p1, p2, and p3. By having this, I'm going to have a lot of advantages. Why? For example, let us assume p1 is being executed by CPU, OK, p1 is being executed by CPU. Now P2, Let us assume P2 needs i, okay? Now P2 can undergo I0 from some of our sum, which means it can read data from some of IO devices, some IO devices, okay? Now, and P3, P1 is done. P3 can continue with CP, which means what I'm actually doing is I'm actually making both CPU as well as IO devices to work in parallel, right? Whereas let us assume if I restrict my computer to say I can have at max when only one process which can be present in the RAM. Right, then what I will be doing, I'll be placing one process inside the RAM, one only after the completion of this process, I'll be fetching that next process from the hard disk. That disadvantage with this is let us assume P1 needs I will. Now whenever P1 is doing IO, our CPU will be idle, right? See, execution and I work cannot be done at the same time for a particular process. We can be done for two processors, which means when a process is being executed by CPU, we can actually perform evil for another process that can be done ok. But here, since we have only one process in the RAM, one year after the completion of this process may be able to take the next process from the hard disk. Ok, now because of this, we are going to have less efficiency, efficient CP efficiency, okay? Cp efficiency is nothing but useful. I'm off CPU. Dividend paid total time of CPU. Which means out of the total time you have got, how much time are you really using the CPU? Write in case if the efficient CPU efficiency is a 100% age, which means we are not actually having the CPU idle. We are using the CPU completely, okay? And in that case, the computer will be very fast way. See, we need to make use of the resources as much as possible, right? For example, let us assume if five people are working in a project. If all five of them work together at the same time, if all five of them worked together without taking any rest, then the project will be completed very fast, right? In case if one or two of them take some risks or be idle, which means they are actually not working to their full potential. In that case, it will, it will take more time for the project to get completed rate. The same is what is happening here. We need to execute lot of processes. And if we make use of our resources, resources means CPU, I will devise or anything. If you make use of it completely, then actually are computer will become faster. Why? Because more processes are being executed at the same time. Which means if one of the processes being executed, another process can undergo I0. So our computers fastness will improve right now. That is not possible in our batch operating systems because max will be taking only one process and one layer after the completion of this process, you'll be taking the next process from the hard disk. Ok, that is a disadvantage. Come into batch operating systems. No, we have one more operating system, multiprogramming operating systems, which is very popular. Multiprogramming operating systems is nothing but B can have more than one process in the RAM. So far, whatever we have seen, which means we, we said that we can have more than one process in their own right. P1 is being executed by the CPU, then one of the other process can undergo Iwo, okay, that is what we mean by degrees. That is what we mean by multiprogramming operating systems. Why? Because we are having more than one process inside the RAM, this is going to improve. One thing is CPU efficiency, which means useful term by total term is definitely going to improve. Which means if one of the processes undergoing I go, I can actually use some other process. I can actually execute some other process, which means I'm not allowing the CPU to remain idle, right? So CP efficiency is going to improve because of multiprogramming operating systems. And also the computers fastness will improve. As the CPU efficiency increases. The computers fastness will also improve, which is very obvious right? Now. We have one more operating system which is nothing but multi-processing operating system. See so far whatever we have seen, either batch wise or multiprogramming, where's the number of CPUs is only one, ok, in our computer, which we have seen for batch ways and multiprogramming ways that can be one, only one CPU. But in multi-processing, where's we can have more than one CPU. Okay? See. We, so far, whatever we have seen, we had only one CPU and we kept on taking the processes and then it is being executed. But in multi-processing operating systems, if more than one CPU is present, what can happen is if one, while one process is being executed by the CPU, some other process will also be executed by this another CPU write. Actually what we are doing here is parallel processing. Parallel processing means beer executing more than one process at the same time, right? But in multiprogramming or operating systems, we are not doing parallel processing, right? We were actually doing concurrent processing C, there is a difference between parallel processing and gotten, gotten processing. That is a difference between Battle and processing and concurrent processing. If, let us assume we incase if you have only one CPU and if we keep on changing the processes and if we keep on executing, then we say that there's concurrent processing. Let us assume there is a mother who is actually feeding her two children using both her hands with this pawn. Okay? He has taken two spoons and then she's feeding both her children, which means she's giving food to both their children. Now, this is nothing but parallel processing. What is happening is she's giving the food to both her children at the same time using both her hands, right? This is what we mean by parallel processing. Whereas in case if she uses only one hand and if she gets what, she gives 1 ahead one offer children and if you use some another one to some other children and she'd be if she keep on doing it interchangeably, then b theta that S concurrent processing. It's a very funny example, right? So, but still it is, it actually helps to understand. So that is the difference between parallel processing and mult, concurrent processing. That disadvantage with parallel processing, deceit definitely parallel processing will be faster than concurrent processing. That is for sure, right? But actually the disadvantage with that is in parallel processing, the system cost will improve, will increase, right? The system costs will increase because we are having more than one CPU. The cost of processor is very high today, right? In case if we have two processes, the systems cost will become very high. So that is a disadvantage. We haven't multi-processing operating system. See whatever we are using today in our computers is multi-processing operating systems. Why? C, you should have here that octopus or upto code processor, quad core processor, right? What does when make quad-core processor? We have four processors which are placed in our computer. That's what we mean by quad-core processor. Whereas octa core processor means we have eight processors which are placed in node computer. Ok? So that is all this. We all operate. All computers we are using today is nothing but actually working on the basis of multiprocessing OS, right? Fine. So these are the various types of operating systems we have. Okay? So what are the things we saw? We saw what is meant by a degree of multiprogramming, which is nothing but the maximum number of processes which can be present in the RAM. Then we saw something called us, then sv. So what are the various, what is meant by CPU efficiency? Cpu efficiency is nothing but useful time of CPU divided by total name ACP of which means what is the total fraction of time which fear utilizing the CPU out of the total time. That's what CPU efficiency means, right? As the CPU efficiency increases, which means as, as, as much as you are using the CPU, utilising the CPU's time, the more faster the computer will be. Ok, that is what CPU efficiency actually, why CPS efficiencies very important. Fine. Then we saw something of what are the various types of operating systems. Bachelor S is nothing but we will be having only one processor and we will be having at most one process inside the RAM. That's what we mean by pathways. And pathways is very, very slow because the CPU efficiency is very less. Then we saw multiprogramming operating systems. In multiprogramming operating systems, we can have more than one process in the RAM. And so it'll, multiprogramming operating systems will be much faster than batch wise because the CPU efficiency is much better. Whereas multiprocessing, multi-processing operating systems, we can have more than one processor and also more than one process can be present in the RAM. See in multiprogramming waves, we can have what max one processor, but we can have more than one process inside the RAM main multi-processing operating system. We can have more than one processor as well as we can have more than one program in the RAM. Now, multi-processing operating system is definitely faster than multiprogramming OS. But multi-processing operating system suffers from a disadvantage that the system cost will increase. 8. An Important point to note: Well, so far we have seen three types of ways aside. We have seen bad too, as we have seen multiprogramming lawyers, and we have seen multiprocessing ways, right? Among these three OSS throat this course, we will be using only one ways and nothing. That is nothing but multiprogramming. Goya's, which means there is only one CPU inside of a computer and our RAM can have more than one process at a time. Okay? See, this is our CPU. This is our RAM. Let us assume this is our hard disk, ok. This is our hard disk, this is our RAM. Now, in case if I have more than one CPU, the nice aid, this is multiprocessing wireless right now in case if you are one year, one CPU, but we allow more than one process inside the RAM at any point in time. Then we said that does multiprogramming ways. Whereas in case if a rustic that there should be only one CPU and that should be at most one process inside the RAM. Then we say that is batch ways, right? These are the three types of waves as we have seen so far. Now, among this, throughout this course, we will mostly be using something called as multiprogramming OS, OK? By default, in case if there is a change, I will let you know in say the video. Okay. But in case if I don't say which kind of voice I'm using it, you always assume that we are going to use multiprogramming ways, okay, fine. 9. Process Control block: So, so far we have seen that whenever a user opens a program, your process will be created, okay? Which means when it gives for user opens a program three times, three processes will be created for that same program. Right? Now, this program for which the process is created is also called as passive entity. Okay? It is also called as passive entity. Whereas here, the process which is actually created for the program is also called as active entity. The name itself suggests, right? The process is actually active, which means it is being executed by the CPU, whereas our program is not doing anything right. It is simply creating the, once the process is created, then actually we are not using the program by actually we're using the program for further creating processes. But apart from that, we are not using the program anything for anything else, right? Only, only we are using the process, which means we are moving the process to RAM and then the process is being executed by the CPU. And all right, so this is 1 I wanted to discuss. Okay, your process is also called as active entity, whereas a program is also called as pass-through entity. Finally, now, not no further. We know that for every program a process will be created whenever user opens the program. Now, the process will not only contain program, it will also have some more thing, right? See, this is, this is a process which is created for a particular program, okay? We know the process will definitely contain the program. Now apart from program, it will also have some more things. See, our program will be full of functions, right? Our program will have a lot of functions, for example, or program will have lot of functions. I know within a particular function, there is, there are chances of having function calls, which means within the function your phone, I can have a function call, say F2, which means and calling function u of two from function of 4x, from function you have one I'm calling, you have to rate. Now in order to, this can keep on happening, which means nested functions can happen. For example, you have one might call you have to, you have to my colleagues three, you have three might call your four. And this might keep on going right. Now just to keep track of the function calls, we need something called a stack. Okay? That, that is the reason we're having this tag memory C. We are going to have a stack is nothing but just a memory, okay? Now, whenever your phone is called, your phone will be pushed into the stack. Now, whenever your phone calls you have to you have to will be pushed onto the stack. Whenever you have two calls, you have three. You have three will be pushed into the stack. And this will keep on happening. Now, once this is done, the order of execution is nothing but you have three followed by. You have to follow Bay of one, which means you have three will be executed once it is done, if three will be popped from the stack and then you have to will be executed. Once F2 is done, it will be popped from the stack. Once your phone has done this will be popped from the stack. Then that's it. The program has completed its execution, right? This is fired me, you'd be doing. Now for this, we use something called a stack. See every program will have lot of functions and within the function that is a high chance of function calls. Just to keep track of the function calls, we use something called a stack. Okay, fine. Now, our program might also have something called as dynamic memory allocation. Dynamic memory allocation is nothing but allocating memory using malloc CNR. Okay? For example, in C programming, we use two function calls, right? Yeah, malloc and calloc. These function calls are actually used to dynamically allocate memory what is meant by dynamically allocating memory? Allocating the memory at the runtime. Okay, that's what we mean by a malloc CL. Ok. Now, whenever we use this MLR Garcia locked within our program, which means this program, this pence HE, this hey, heap space is actually used for those dynamic memory allocation. For example, in case if some space is allocated using dynamic memory allocation, now this space will be allocated within the space heap. Right? Now, there is no fixed space for stack or heap, which means some programs may need more space for stack, which means it might have a lot of function calls that has some functions may need more space for heat, which means our progress that those programs will have more dynamic memory allocation, right? So they are actually dynamic, which means the heap will be growing upwards, whereas the stack will be growing downwards. Some programs may need more space versus tack, In that case, DAC will go till here. Let us heat will be having only this space. In some programs, heat may need more space. In that case, the heat, heat will be allocated more space, something like this, where the stack will be having very little space, okay? In simple words, what I want to tell this, this base is not equally divided between stack and heap. It really depends on the program. Some programs may need more space for stack, where some programs, most space for stack, but, uh, some programs may need more space for heap. So the amount of space which is allocated to stack or heap among this total space really depends on the program itself. Ok, it varies from one program to another. Fine. Now this complete process, which is created for a program is also called us Process Control Block, Ok. It is also called as process control block, PCB. Now for every process, we will be having a process control block. In case if we have ten processes, then we will have, will be having ten process control blocks. So in here, our morale, This is allowed CPU and RAM. And as of now, there are three processes named P1, P2, and P3, along with the waves quote In the ramp. Ok. Now this p1, p2, p3 is nothing but the PCP, which means this is PCB of p1. This is the PCB of P2, and this is the PCB of P3. Ok, fine. So, so far we have seen that your process will not only containing just program, but it will also have some more things like stack, heap and static and global variables. See what is meant by static and global variables. Within our program. B might use static keyword, right? For example, in case if I wanted to declare a variable, declared a variable S tactic in IE. Okay? These variables will be separately placed in this static variables C. In case if it is a local variable, what is meant by a local variable? A variable which is defined within a function is called as local variable. Right? Now for local variables, the space will be allocated within the stack, which means we are already seen that all function calls will be stored within the stack. Now in this activation record Fourier F1. Water are the variables which are created for your F1 will be placed, okay? All the local variables. Similarly for F2, there can be lot of local variables. All the local variables of You have to will be placed over here. This is how local variables are allocated, but the variables like static variables are global variables will be allocated separately, okay? They will not be allocated within the stack. They will be allocated within a day, will be actually allocated in a particular space inside the PCB. Okay? This is what we mean by process control block, fine. Now in case if you didn't understand the static and global variables, you might have to go through the basics of C programming, OK, in case if you go through the basics of C programming, you will be able to get this. 10. Attributes of a process: Now let's see what are the various attributes we have for a process, okay, attributes is nothing but Properties. C, For a, for example, if I am a person, I may have a lot of properties like my hardest curling, my skin tone is brown. I'm wearing glasses liquid. I had a lot of properties for me in a similar way, for every process, there will be some attributes, okay? Every process, first thing is nothing but process ID. Process ID is nothing but a unique number. Every process will be assigned a number, and that number will be given to only this process and not to any other process. Ok, that's what we mean by unique, which means every process will be having a unique number. And that number, we also say that does process ID. Okay, fine. Now that is something called a program counter, program contact. Seeing what, what might actually happen is let us assume this. Let us see this first. Let us assume we have a CPU, OK. And P1. P2 and P3 are the three PCBs of three processes which are placed inside the ramp. Now within P1, P2, and P3, one of them will be executed by the CPU. Write, let us assume on three of them, P1, P2, and P3 wanted CPU, okay? They are ready to, they are in ready state, which means they are ready, picked by the CPU for execution. Ok? Now in that case, CPU might have to select one, not, not CPU operating systems or might how to select one among the three process to be executed by the CPU. That is what we have seen, that is the main functionality of wayside waste functionality is nothing but resource allocation, which means the results here is CPU. Now, the CPU has to be given to one of them, one of the three processes. Now, how is that being done? That is being done by something called us, our operating systems code. Now, the part of the quote COS code is nothing but actually a very big program. You already know that, right? Waves code is a big program. Within that part. There'll be some part of the program which will be actually used in order to, in order to write, in order to defend which among the three processes should be selected by the CPU. And that part of the code is also called as scheduler, OK, scheduler, shade you live. It is nothing but a program which is part of all waste program. This is our ways Program, and this is the program which just scheduler and this should Newland will have the code to say that in case if more than one process needs that CPU, which among them should be executing the CPU first. That is very important, okay, which is executing the CPU first. See every process will of course get the CPU if there is no, no, there is no doubt about that. But what is the order in which they will be getting the CPU? That really matters right? And that is being decided by eventually tuning algorithm, which means that this is, this is nothing but the scheduling algorithm. Ok? This is the quote. Now, this code can be implemented in lot of ways, right? This code can be implemented lot of phase. For example, the, among these, all these processes, whichever process which came to the ram first should be executed by the CPU first. That is one algorithm. We also say that as first come, first serve scheduling algorithm. What is meant by scheduling algorithm? The algorithm which is used to actually select one among the process, one among these many processes to be executed by the CPU. That is what we mean by scheduling algorithm, right? There are various scheduling algorithms and one such Annealing Algorithm is first-come-first-served circling algorithm. Now what dish annealing algorithm will do is among all the processes which are present inside the RAM, it will choose the process which came first to the RAM. The process which came first to the ram, which means let us assume P1 came to the ramp first before p2 and p3, then P1 will be given the CPU first. That's what will come for sure for associate dealing algorithm will do. In a similar way. We have lot of shooting algorithms. For example, that is another scheduling algorithm named as shortest job first scheduling algorithm, which means among the three processes, let us assume P1 needs five nanoseconds of CPU, OK, to complete its execution. See these problems you'd be seeing, seeing it in a more detailed way. Now we are just having a rough overview. Ok. Let us assume P2 needs three nanoseconds to complete its execution, and P3 needs two nanoseconds to complete its execution. Now, among these three, the process with the shortest time shot tested, short tester execution time will be executed first. That's what shortest job first scheduling algorithm says. Okay, shortest job first scheduling algorithm says, whichever process is having the shortest exit habitual process which is recurring, the shortest execution time should be executed first, okay, now, among these three, P3 needs the shortest execution Crime Time, right? It needs only two nanoseconds from the CPU, whereas P2 needs three nanoseconds from the CPU. P1 needs five nanoseconds from the CPU. So P3 should be selected by this year, by the scheduler to be executed by CPU first. Okay, so this is just a rough overview. Again, we'd be seeing this should routing algorithms in more detail with a lot of problems. Finally, know why i have explained these things is just to explain you that what is meant by program counter, okay, now what might happen is let us assume some process is being scheduled Scheduler by the scheduler, the, let us assume some process is being scheduled by the scheduler to the CPU, ok. Let us assume cp is actually executing process P1, okay? Now what might happen is there might come some other process. Let us assume process P4. Let us assume we are using shortest job first scheduling algorithm, which means the process with the shortest execution time will be executed first, okay? Here P3 has the shortest execution time. So they see the schedulers scheduled process P3 to the CPU, okay? Which means CPU is actually not executing process p3. Now, let us assume a new process, P4 comes into the RAM, ok, now this needs, let us assume just 0.5 nanoseconds from the CPU. Now what we should be doing is this is actually a lesser time than this, right? This needs lesser amount of CPU, whereas this, let us assume P3 needs more amount of CPU, okay? Now in that case, this process P3 has to be forcefully stopped, which means this process has to be stopped from executing, execution of CPU, okay? And some other process, P4 has to be scheduled by the scheduler, OK, C0, P3 is not yet completed. Okay. P3s knotted completed, but it is stopped for some temporary for some temporary amount of time until P4 is getting, getting completed. Now once P4 is done, we will be executing P3. Okay? So what we are doing here is whenever we are executing a particular process, in case if a higher priority process comes here, higher word here, priorities being calculated based on short test to job, right? Whichever is the shortest job, that there'll be given the higher priority, that there'll be given the higher priority that'll be executed first. Now here, since once the Havens, a high priority process comes into the RAM, the low priority processes being preempted. And we take the high priority process and then we execute it. Ok. So what is actually happening is so once P4 is done, we might have to continue with p3, right? C1s, P4 is done, P3 is not completed. One, leave some part of P3s completed, and then we moved to P4. Now once before is done, we might have to continue from there where we left off P3, C0. P3 is a program. It will have lot of lines. Let us assume while executing this part, b actually preempted P3 and we showed you before. Now, once P4 is done, we might have to continue P3 from the place where the left out. Okay, so how, how is it possible? How, how will we be? Remember the place where we actually left out? Now for all these things, we use something called these properties. Ok, program counter will actually say the instruction number. Instruction number is nothing but line of program from where I need to continue the execution. For example, this is first-line in the program. There's a second late in the program. This is third late in the program. This is fourth leg, this is fifth line. Let us assume we have executed p3 tilde third lane, and then rescheduled P4. Okay? Do because P4 is having higher priority than p3. Now, let us assume P4 is done come execution of P4 is done by the CPU completely. Now we will be again moving to P3. We need to start execution, execution from line number four. Now how will we know that we will start the, we should start execution from line number four that is being indicated by somebody, something called us program counter. Okay. Program counter is nothing but a register, a register which will be named maintained it closer to the CPU, okay? This is also called as program counter. This register will hold the numbers. So, so far near seem that when process P3 is being executed by the CPU, let us assume p, process P4, which is of higher priority, came to the ram, okay? Now we might have to preempt to p3, which means we might have to forcefully stop.py CPU from executing P3. And then the scheduler will schedule process people now before it is being executed by the CPU, okay, some letters until line three of process P3 is done, and E4 is being scheduled, ok, now once before is done. We might have to proceed from line number four off p3. Now this line number four is being remembered, is remembered by something called us program compare. Now similarly, general-purpose registers actually remembers which are the register values which are used by process P3, Okay, see process P3, what will have well executed when it is being executed by the CPU, will, should have used some registers. For example, this register is having a value of five, this register is having a value of six. This registered as having the value of three. This is having a value of two, okay, until lined, until the execution of line three. These are the values which are being stored in the register. Now, these values has to be used, will be used by IP3 while executing line number 45. So these values have to be somehow, remember, okay, but v, When we continue with P3 after completing P4, right? Now for that purpose, be actually store all the register values. Okay? That is what we mean by general purpose register for every processes. For every process, we will be having a set tough register values. And these registered values has to be remembered whenever we are preempting that process from execution by the CPU. Why do you do scheduling algorithms? Okay, fine. Similarly, the, There'll be a list of open files, which means the files which are opened by process P3, that has to be also remembered. Okay. See files are there will be some files for a, we should have seen that what is meant by Ivo write I0 is nothing but reading something from some IO device, especially reading some files from, from the IO devices. Now this process P3 should have actually open some files. Open means it should have started reading some files. Let us assume it has read half of the file after executing line number three until executing line number three. Okay, now the reading of the file from the leftover part has to be continued, ok. For that reason, B, remember the list of open files which are being done by a, well, for burdened by the process of done for the process P3. Okay, but you'd be remembering it. Similarly, we have list of open devices. For example, process P3 should have used the printer for printing a page. Ok, now, until the, let us assume for printf, for printing a complete page, we have printed half of the page. Ok. Now process P3 is being preempted, being premed admins being stopped forcefully from execution by CPU, and P4 is done. And once before is done, P3s printing has to be continued from the place where we left out. Okay, so we use something called us this stuff, open Devices, which means the devices which are being opened by process P3 should have been remembered when we continue after being preempted. Okay, so we use this. Now what is meant by production is a went up. A particular process has some space, right? It has something called a stack space and heap space, which means for function calls, it uses the stack space and for dynamic allocation, for, for dynamic allocation of space, it uses the heap space. Now, a process, the process P3 will have a particular taxpayers and heap space. And process P four will also be having its own stack space and heap space in its PCP right? Now, P4 should not access this space, as well as this process should not access this space, okay, that is what we mean by production. And for every process, our operating system needs to make sure that it is not using the space of a process, is not using the space of another process. Ok? That is what we mean by attributes. I know it is a bit difficult to understand it very clearly the first go. But as we keep progressing, you will be able to understand most of the things. Ok, fine. Now these are the various attributes of a particular process. Now let's see a very interesting topic named does scheduling algorithms, CPU scheduling algorithms, okay, fine. 11. Types of scheduler, Context switching: So, so far we have seen that every process will have a process control block, which means every process is, itself is nothing but a process control block. And it will also have some attributes associated with it. Unlike process ID, set off all files opened by eight, then program counter, all the program counter values all these things right? For, for, for every process we will be having a PCB and then attributes, okay? And then the PCB and attributes of a process. Collectivity is also called as a context, okay, contexts of a process. Ok, see, we have seen what a PCB is great. A PCB will be having program code here and then you'll be having stack and static and global variables. Then we'd be having stack and heap or hit OK. Now this is what we mean by air PCB of a process. Along with that, we will be also having something called US attributes like process IT, AM list of open files and all these things, right? All these things up a particular process, say process P1 is also called as contexts of the process p1. Ok, so for every process there will be something called as context. Fine. Now let's come to this. Now from this we are, so far we have seen that a pro, there'll be large. Let us assume that a lot of programs in RAM. First of all, we have voice, then we have p1, p2, p3, okay? Now, within these three processes, whichever process should get the CPU first IS being visited by the scheduler. That's what we've seen so far right? Now. That program that scheduler is specifically called as short-term she'd unit. Okay. Lets you do let us also called the short-term scheduler. Ok. Now, that short-term should you learn, will be part of our Waves code. We have already seen it. Okay? Now, now we know that from hard disk we move some programs into the ramp rate. We may initially the process is being created, which means the process is induced TDD, where once a user opens, a sub program, process will be created, which we said that the processes in new state, now there'll be a lot of processes which will be new state, right? There'll be a lot of processes in new state. Now within these, among these processes, we can only move, move a few processes into the RAM, right? Because capacity of RAM is much lesser than the capacity of hard disk. Now, among these various processes, which processes should, which group of processes should be moved into the RAM? That has to be again decided, right? That is also a, what we mean by resource allocation. We have seen in the earlier part of our course, maybe in the second, second lecture, our first lecture, we have seen it right. Now. These projects, these RAM is a resource which has to be given to only few processes among the, all these abating processes, right? This, and know which processes should be moved into the RAM is being decided by something called Ernest long-term scheduler. Ok, long-term scheduler is itself a program which will be part of our operating systems program. Now this long-term shed a little saying among the processes which are being created inside the hard disk, which are the processes which has to be moved into the RAM. Only few processing. Let us assume that our file processes which are created inside the hard disk. But we have only Spacewar, only two or three processes in saved that RAM out of the file processes. One lead to R, three can be moved into the RAM because the capacity of free space in the RAM is one, can hold only two or three processes. Now, which two among the file has to be moved from hard disk to RAM is being decided by a program called us short-term showed you that, okay, fine. Now let us assume our RAM is full, okay? Our RAM is being completely occupied by using four processors and end to P1, P2, P3, and P4. Let us assume a new process, P5 is being created, okay? And let us assume that every process will have something called as priority, okay, we have seen it, but reality is a number which is given to every process we have seen in attribute side, see, every process will be given a number, say process P1, P2, P3. Let us, us in P1 is given a number and seven, p2 is given a number, S6, p3 is given a number as three. Okay? Now, let us assume the process whose priority number is greater should be given the higher precedence, higher priority, which means p1 is having higher priority than p2 because seven is greater than six. Similarly P one is also greater than the P1 should be given higher priority word P3 because seven is greater than three, okay? So among these three processes, p1 is having the higher priority, Okay? So every process will be given a priority number. Ok? Now let us assume P1, P2, P3, and P4 are having some numbers. Let us assume p1 is having an ampere one, P2 is having a number two P3s having an unprepared P3, P4 is having a priority of four, and P five is having a priority of five or so. Now, in case if P5 comes into the RAM, p53 will be executed first. Once p with phi comes into the ramp, p53 will be preferred before p1, p2, and p3 and p4 by the sheet unit, right? Because P phi is having higher priority than these four processes. But the problem here is RAM doesn't have any space for P5. We cannot move PFA from hard disk to RAM because this base is already being occupied in say, the ramp. Now what we should be doing, what we should be doing is we should be moving one of the processes in the RAM into the hard disk. And we should be moving the high-priority process, which is p phi from hard disk to RAM. There is no other way, okay? And we should always GW, GW more importance to high priority process, okay? Hyper EIRP or D processors should always be executed first before lawyer priority processes. So the only way to do this is we need to move one among these low-priority process into hard disk and we need to move the high priority process into the RAM. Ok. Now, the decision which B might have to take here is among these four processes named P1, P2, P3, and P4 beach process, are you going to move to hard disk? Ok, see we need to move one among these processes into hard disk so that we can bring p phi into their debt free space, which is being freed right now, okay? Now, which among these four processes have to be moved to hard disk that should be decided. And that is again decided by your operating systems. And the part of, the part of waves which dictates that is also contexts medium term sheet you are okay. Medium-term scheduler is itself a function or a module which is presenting said ROS code, which will decide which process should be strap out of the ramp so that the high priority process can be swept into the RAM. Ok, swap OK means boiling a process. The ramp swapping means moving the process into the rap, okay, that is the difference between swap out and swapping. Ok. So this moving out and bringing in is also called as wrapping C. We actually mode a low priority process from RAM to hard disk and remoter hyperactive process from hard disk to ram rate. This processes are so-called called us wrapping. Okay? This, this, this, this exchanging is also called a swapping, fine. And this is being done by something called US medium-term Shatila. So, so what, what, what we have seen so far, long-term should look, short-term, medium-term should you learn. Now out of among the number of among a lot of processes, which processes has to be moved into the ramp and how many processes has to be moved into the RAM is being decided by long-term Shi Du Lin. Okay. Now, once the processes are placed inside the RAM, which process should access the CPU first is being decided by short-term, should you learn? Okay? Now, whenever our high priority process is being created in the heart is one of the low priority processes has to be moved into the hard disk. Now, which among these processes should be moved into the hard disk is being decided by something called as medium-term should you learn, okay, fine. You know, whenever we are execute, let us assume we are executing a process when CPU is executing a process P1, okay? Or short-term scheduler or simply, we can even say that a c, short-term should you learn to be simply call it ushered. You'd have no issues, okay? Because short-term shareholder is takes the most important decision and that is which process should be executed by CPU next, okay, that is very important. And so we simply say a short-term should you learn scheduler? Ok. Now, let us assume process P1 has been scheduled by the short-term. Should you learn to CPU? Ok, now, let us assume a new process. Let us know we are having only P1, P2, and P3. And P3 is being scheduled by the scheduler to be executed by CPU. Let us assume high priority process it P4 is moved into the RAM, OK, which means P4 is having higher priority than P1, P2, and P3. Ok, let us assume that. Now in that case, what we will be doing is we will be preempting P1, and then we'll be scheduling P4 so that we will continue P1 after execution of P4. Okay, that is what we have seen so far. Now, this process of this, I don't know what they have done is we have preempted P1 and we are taking p4. Actually what we will be doing is we need to save the context of P1. Why? Because we need to continue P1 rate. So we might have to store the PCB as well as attributes of P1, which we also say that this context of p1, right? Context of P1 has to be saved somewhere in our computer. And then we will continue with P4. Okay, why? Because after finishing P4, we might have to continue P1 from where we left, right? For that we might have to, we should have saved P1's context, right? That is what we mean by context switching, okay? This entire process is also called as context switching, which means whenever a new process, let us assume, whenever, let us assume CPU is executing P1 and P4 is whenever P4 comes into the RAM whose priorities hire them? P1. P1 has to be preempted. Bb, and P1's contexts has to be saved, and P4 has to be scheduled to the CPU, okay, this entire process is also called it as context switching. Which means we are switching the contexts, which means initially we were having this context of P1 in the CPU. Now we are having the context of P4 in the CPU because we have switch the context. Okay? Finally. 12. Various times of a process: So before seeing all these concepts, okay, what are the various types and all this? Let's see, what's the difference between point in time and duration and time. Okay, what is the difference between both these towns? So again, it's understanding the stubs first. Ok. Let us assume that is a person. Say, yea. Okay. The name of the person is cAe. Okay. He's go He's planning to go into office. Ok. Let us assume he has reached the Office, which means he has entered the office at 01:00 AM. Okay. At one name, he has entered the office and then he worked till 03:00 AM. And he left the office at 03:00 AM. Okay. He left the office at 03:00 AM. Fine. Now, this no. When did he when did he arrived to the office? He arrived to the office at 01:00 AM. Okay. This one AM is also called as point-in-time. Why? Because it is a single point, ok. One name is a single point in time. Now similarly binded he leave the office, he left off is a 3m and this three M is also a point in time. Okay. Now, how many ours did he work in the office? He worked in the office. Fun to us. Right. This duration of time from 10am to 3M is what he worked firm. Now this duration is nothing but to us. Now this to us is also called as duration in time. Okay? He's working time is nothing but duration in time. So that is a difference between point in time and duration and time. Okay? Now let's see these things. Fine. Now, we know that here we initially that by a program will be completed from source program to machine program. And then it will be placed inside the heart bys, then it'll be mode into the RAM. Then once the process is in gram, it can be either executed or the I0 will be done for the process RAW, waiting for some event to happen. All these things, okay, this is what we have seen before. Now, at some point in time, a program there'll be a process will be moved from hard disk to ramp. Okay. That point in time. I am not saying duration in time. I'm saying it is point in time. That point in time at which the process is more from hard disk to RAM is also called as arrival time, ok. It is also corridors are every time an event time is nothing but it is a point in time at the time at which your process has RL to the RAM, let us assume it is 2m, okay, at two AM, your program has arrived from hard disk into RAM. That is what we mean by arrival time. Okay, finally, now once a program has arrived into the RAM, what can happen? This program will be executed for sometime by the CPU. It will be executed buys for some time by the CPU. Now in case if a higher priority process comes into the RAM. This process will be preempted, which means this blocks will be stopped for some time and the high priority process will be continued execution rate. Let us assume p1 is being executed with your CPU. Then a high-priority processes P2 came into the RAM. And so we have preempted T one and we have continued with P2. Okay, fine. And now what we want is actually doing. It is actually waiting. Ok. It is not, it is neither executed by the CPU nor it is undergoing Aibo. It is actually simply waiting to be executed R2B for Iw. Okay, does a waiting for one, either being it is waiting for execution, are it is waiting for IO. It is not doing anything productivity as of no, it is actually ideal. Okay, this processes idle inside the RAM, which we have already seen before, as it isn't ready state or it is waiting, are it is actually baiting. Ok, fine. Now, now the, the, the bam, we have already seen that the time at which let us assume the process has arrived into the RAM at one AM, okay? Now, it has completed its execution, which means the entire process is done at three AM. Okay? Now this one AM is called as the arrival time, which means this is the time at which the process came into the rap. Okay. And this is the time the three 3m is also called as completion time because this time, at this time the process has completed its execution and this process can be removed completely from the RAM, ok, this is also called as completion demand. Completion time is also a point in time, ok? Now this to us, which means the time at which the process, from the time at which the process came into the RAM in the process has completed its execution. This to us is also called as turnaround time. Ok, it is also called as turnaround time. For computing turnaround time, we have a formula, okay? We have two formulas actually. Completion time minus i don't even at a time. Which means here it is 03:00 AM minus one I am. It is nothing but to us. Okay. The turnaround time is two R C turnaround time is a duration and time that's four. That's for the unit is hovers and it is not a l. Whereas completion time is a point in time. Are able team is a point in time. That's why the unit of completion time is am, the duration, the unit of arrival times cm. But still the unit of turnaround time, which is to house the unit is nothing but how is right? It is not AM finding. So turnaround time is nothing but the duration the duration of ten in which the process is inside the ramp, okay? The total time at which the process is inside the RAM, it is also called as turnaround time. Fine. Now what is meant by weighting them? See in this turnaround time, what are the things which could, which could have happened? For example, there is one possibility is process P1 might have been executed for sometime. Then a higher priority process came into the RAM. And so we Priya, and so we preempted P1. Then we could have started with P2. Okay? Then once p2 is done, we could have again started with P1. Then let us assume hyperreality processes p3 came into the RAM. And once P3s done BY again continue to p1, let us assume P1 has completed its execution at 03:00 AM, okay? Now, in this thing, what are the things which, which are which have happened? P1 is nothing. P1 has executed for the stem, and it has waited for this stamp, which means P1 has waited for this time. And P1 is again executed for this time. And again, P1 has waited for this time. And again P1 has executed for this time. Ok, so actually what has happened here is in this turnaround time, this turnaround time can be computed by heat, can be cut turnaround time. There is another formula for turnaround time. Okay, I'm writing in shortest TED does turn around time is equal to burst ten plus xy burst m plus, I wrote them. Burst m plus I wrote them plus baiting them. See here we have not included here, here we have not actually included I, okay, see there is a chance that your process might not need Io itself, which means it comes in to the ramp, it waits for sometime or it executes and then it completes. Okay. It doesn't need any Ivo, okay, which means it doesn't need to read or write into any of the IO devices. That is also still possible for a process rate. It is there is no compulsion that every process should do. I vote, right? That is what is happening here. Now let us assume we here we have assumed that, well, I wrote m is 0. I wrote M is also a duration in time, which means the amount of time, let us assume three hours or four hours is the time spent by this process in performing IPO in which means in reading some from reading or writing from some IO devices. Okay, that is what we mean by IO time. So we can say that turnaround time equal to burst ten plus ten plus waiting time. Okay? This is one formula also be at, this formula is also connected, okay? Turnaround time equal to completion time minus re-melting. Fine. Now after turn out on time, we have something called us waiting ten again. Now, what is the waiting time of one year? One has waiting for, waited for this duration, as well as P1 has waited for this duration, okay? These two times, okay? How will you compute the duration here? This minus this, for example, the, this is 2m, and if this is 01:15 AM, 2m minus 150, you name is nothing but 45 minutes. Okay, here it is particular units. Similarly, we can also computed here. And if you add these two duration of time, we can compute the waiting time of process P1, okay? Fine. C In case if you didn't understand this very clearly, we are going to see a company, this is not actually a problem, okay? This is just an example to explain the concepts. We will see a complete problem. You'll be able to understand all these things very clearly, okay, final. So reading them as nothing but the time spend by a process in the RAM without actually executing, as well as not performing I evil. It is simply mating and said the ramp to be picked by the CPU for execution in the future. Okay, that is just is really actually a, their process is ready to be executed, are performing Aibo. But due to lack of resources, it is actually waiting. Again, that's the amount of time which is spent by a process in waiting. We say that US waiting time. And waiting time is a duration in time. Okay? Waiting time is a duration in time frame. Now we have something called as the response time response limb. You'll see a bit later, okay? Even if I say this will not be able to understand it a bit later. Now we have something called us IO time. You already know it, right? The amount of time which is bent by a process in performing IO after retest RL to the RAM until its completion is a called as I wrote him, ok. For example, if process P1 has arrived to the ram at one AM and it has completed its execution at three AM. And in case if it has spent from to a 2m, two to 15:00 AM in performing IMO, then IO time is nothing but 15 minutes. Ok. Io time is also a duration in time. Okay. Find these are the various times we have. We didn't see why only one thing and that is corresponds to m, okay? We will see it a bit later, even if I tell it now, you might not be able to understand it very clearly, okay? After seeing an example, you'll be able to understand response, TIM. Okay, fine. 13. Types of Scheduling Algorithms: Let us see the various types of scheduling algorithms we have. Ok? We shall see each shading algorithm one-by-one. Before that, they set off all scheduling algorithms we have can be classified into two types, okay? Preemptive scheduling algorithms and non-preemptive scheduling algorithms, okay? The name itself suggests what they are actually right. For example, what is manmade non-preemptive shading algorithm as, let's come here. See let, let us assume this is our RAM, OK, this is our RAM and v. As of now we have four processes, P1, P2, P3, and P4, Okay? Now, what non-preemptive scheduling algorithm says is in case if one-off, let us assume we have only three processes. Ok? Let us assume we have only three processes as of now inside the RAM. Okay? Now, how non-preemptive scheduling algorithm works is in guess if one, let us assume P1 has starter. P1 has been scheduled to this CP, okay, now P1 isn't running state, which means it is being executed by the CPU right now. Now, during this time, let us assume there is a process named P4 which came into the RAM, ok. And let us assume the priority of P4 is higher than that of P1. Okay? Priority of P4 is higher than that of P1. Now, should I preempt P1 and start with P4? Should they continue P1 as it is? That is the question, ok? In case of non preemptive scheduling algorithm, we will never preempt a process until it is completed in case if we have started it, okay, in case if I am started it, for example, we have actually started p1 here right before P1 has arrived. Now. Now even though P4's priority is greater than that of P1, we will still not preempt T one because it is a non-preemptive scheduling algorithm, okay, one layer after the completion of P1, we will check which process among these has the highest priority and then we'll pick, okay? But once a process has been started, once a process has started executing, execution, we will never preempt it until completion. That's what non-preemptive scheduling algorithm means, okay? Now what is meant by preemptive scheduling algorithm? Prim in preemptive scheduling algorithm, we can preempt the process, right? For example, if p1 is being executed by the CPU and in case, let us assume P4 has come into the RAM and our prayer dF p four is greater than p1. Now in this case, what we will be doing is we will preempt p1 and then we will she dude P4, which means the scheduling algorithm with shed you'll pay for. Okay? So that is the difference between preemptive scheduling algorithm, a non-preemptive scheduling algorithm. In non-preemptive scheduling algorithm, in case if you have started execution of a process, we will never preempt that process until completion. Okay. If I now have a look at this point, CPU scheduling algorithms are applied one-way, two processes which are inter ready state, ok, c. Let us assume there are some processes inside the RAM. We have processes P1, P2, P3, and let us assume process P4. Okay? Now we know that any process in the RAM can be either in a ready state. It can be either in ready state. Are it can Dean IMO state art can be in running state, right? Let us assume process P1 is in dining state. Process P1 is in running state means p1 is currently being executed by our CPU. And let us assume processes P2 and P3 are in ready state, which means processes P2 and P3 are inside the RAM, but they are neither undergoing Iowa, nor they are being executed by the CPU, but still they are waiting inside that Rahm idle. Ok, fine. Now let us assume process P4 isn't. I will state. Fine. Now, my question is, as of now, let us assume we are, we are actually having non-preemptive scheduling algorithm. Okay? Non-preemptive scheduling algorithm. And one more assumption is that the priority of process P4 is greater than both P2 and P3, Okay? Priority of process P4 is greater than b2 and b3. Now, as of now, P1 is currently being executed by the CPU, so there is no chance of preempting process P1, right? That's what we mean by non-preemptive scheduling algorithm. Doesn't matter what the priority of P1 is. In case if you have started P1, we will never preempt it until completion. Finally, let us assume process P1 has been completed, okay, fine. We are, we have already seen that whenever a process has completed its execution, that process will be completely removed from the RAM. The process has been completely removed from the ramp. Now my question is, now, our shed dueling algorithm might have two, might how to share deal one-off the process to CPU, right? That's what osha routing algorithm will do. Which means now the No, my question is, which process will lower scheduler should yield to the CPU? Among these three processes, which process but lover, scheduler, schedule to the CPU. Now you might say that process P4 will be scheduled within scheduler because priority of process P4 is greater than p2 and p3. But that is actually not correct. Okay. White sea process P4 is in idle state. Okay. What does it mean process P4? In, uh, in order to continue execution of process P4, we might have to do some IO, which means process P4 needs some data to be read from some of the IO devices, which means they can be either hard disk are it can be printed or any IO devices. Fine. Okay. So process P4 might have to read something from one of the IO devices, one only after it is being done, it can further proceed with execution. Ok, so what, what, what are you really mean by this is just xi dueling algorithms. Will one lead paint processes which are in ready state, and one lead within this processes, it will select one of them depending on priority. Ok, it will never consider a process P4 because process P4 is an Aibo stateless c, Let us assume scheduler schedules process P4, Okay? She should you or should use process P4 to CPU. Now can CPA execute p4? No, right? Because P4 needs to undergo I0 only after that it can actually proceed with the execution. So what I mean by this is CPU scheduling algorithms that are played only two processes which are in the ready state and processes Magellan, Iowa State will be blocked. And so those processes will not be considered by shading algorithms while scheduling, ok. And maybe two or three videos back. I already told that if if a process is in Iowa State, females in the various states of a processor and we have seen waiting state iowa state analysis. I already told that if a process is in Io state, we can also say that he doesn't blocked state. Okay? This is the reason for this, okay. If a process is an Aibo stayed, we can also say that as an it isn't blocked state because I hosted on block state both are same. This is because if a process is in Iwo state, then that process will not be considered by the scheduling algorithm. Okay, then plus will not be considered by the scheduling algorithm. Fine. Okay? So warm among the processes which are in ready state, the processor, the scheduling algorithm will schedule the processes. Fine. 14. SJF Scheduling Algorithm: Now, fine, so far we have seen what are all the introduction which are needed for scheduling algorithms. Now lets see one famous scheduling algorithm named us, shortest job first scheduling algorithm. Okay, shortest job first scheduling algorithm. In order to understand this, first, let solve some examples. So here it will make it very easy. Let's first see some theory. Sharpness, George Bush Annealing Algorithm among the array would processes, process with the least burst M or execution TMC, burst time and execution time. Both mean one are the same, right? We'll be given preference. It is a non-preemptive scheduling algorithm. If you know what is meant by non-brain tissue dealing with goddamn right? Also, it is a priority based algorithm. Ok, and why it is a priority based algorithm? It is a priority based algorithm because the process with the shortest burst time will be given higher priority, right? Whereas the process with the longest burst m will be given a lesser priority. So clearly it is a priority based scheduling algorithm, okay? See, priority based scheduling algorithm has some disadvantages, which you will see a bit later. But understand that wij as the M-phase ACH, which started jumper channelling algorithm is also called as is the, okay, why is the IAAF is called as a priority, but it is a priority based algorithm. Ok, understand it. This is because as dF is a priority based scheduling algorithm because the process with the shortest burst m will be given higher priority, finite. Now let's see this example. See once we see this example, this topic is quite simple, okay, you'll be able to understand it. Now, we have already seen in attributes of a process, we have seen what is meant by a process ID, right? A unique number which will be given to every process, which, Okay. So process ids are given 12345. See all the sub-processes, okay, this is one process, this is one process, there's one process and so on. Are able, they are given the arrival time of this process, again, two time units, okay? Bce, the time and the unit for this is time units. Anything, it can be either nanosecond or whatever, a millisecond or whatever. And they have also given the burst timbers Tim is also called as execution time. Okay, you know that execution time, they had given this, they are asked to find the average turnaround time. And waiting time. Wt means waiting ten. There was also as something called us throughput, which we'll see okay, or we have not seen it till, till now. And they also asked something called Does she do length? Ok, what is the length of that sheet you now first, let's see what is meant by average turnaround time. Average turnaround time of all the process has C, Hebrew process will have a turnaround time, Y, c. We know that every process will have an arable tempt to ramp, right? See what is meant by turn-around time. Let us assume this is our CPU. This is our RAM. And this is somewhat hard disk. Now what is meant by turned around time? Once a process has 3e to the ram, we switch on the timer, okay? The timer is initially at 0.0.0, whatever it is. Now we switch on the timer. Now, as long as the process has completed. Once the process is completed, we will switch off the timer, right? In simple words, I can say that in our own time is nothing but the time spent by a process inside the RAM, OK. Which means we are, we have already seen that they are on our own time to completion time minus RA will time. Okay? Using this formula, we can calculate the turnaround time of every process. First process again, process the process and every process I it. Now we should have got the values. Now we need to find out the average. What is average had all the values which we have computed, which means all the turnaround timescale computed and divide it by five because we have five processes. Okay, let's, let's do it. Let's first compute. Let's first draw the Gantt chart. Ok, this is also called as Gantt chart. Fine. This is nothing but 0 time units. Okay? We are starting with 0 time units. Okay? Start, we're starting, we're starting with 0 time units. Now, see one more important point. You need to notice our shortest job first scheduling algorithm will pick the process with the least burst m. That is fine, but it has to be considered that it can pick only processes which has a Rayleigh, right? In case if a process has not arrived to the RAM, then that process cannot be, cannot be taken into consideration by that scheduling algorithm. Okay, that is quite obvious rate, fine. Now see this. Now we have started at time unit 0 now has any processor rabid time unit 0, no process rate. The first process which arrived is P1, which are rabid time unit two. So from 0 till to our CPU is idle, okay? Our CPS idle means our CPU is not executing any process because no process has arrived to the ramp, OK, C120 for process has arrived to the ram. Our CPU can execute it right. Now, since no processes are aimed till this time, we can say that the CPU is idle. Now what is the disadvantage of having CPU idle? By having the CPU idle every Friesian Siebel drop-down rates EP efficiency will go down. As a result of which are computer will become a bit slower. But here we can't do anything because no processes come to the ramp. Okay? Finite. Now let's see. Now at time t2, the only process which has arrived is process P1, okay? See, it is a non-preemptive scheduling algorithm, okay? Have that point in mind. Our SJF is a non-preemptive Shatila radiating algorithm. Fine. Now what time you do one lee process P1 has arrived, okay, see, I'm going to take this as p1, OK? Oneness P1 to P2, three is P3. Okay, process, fine. Now let us assume process. Only one has come again. So I'm starting with 100 time any tool. And it's burst tamer execution name time is for three time units, right? Which means until five, p1 will continue. See, you cannot preempt it within this time, okay, those there might, there might come a new process whose priority is greater than P1. But still, we cannot preempt p1 here because it is a non-preemptive scheduling algorithm. Fine. Now let us assume p1 is done execution right? Now at time unit phi, which are the processes which has arrived. P2 has arrived. P2 has arrived before, five itself has arrived somewhere here, ok? Similarly, P3 has arrived. P4 has not arrived because P4 arrays a time-honored six, but we have reached only till five. Similarly process P failure's not an advocate. Now, among the others, P2 and P3, we need to pick the process with the highest priority. Now, which process has the highest priority? That really depends on which process has the shortest burst temp. Right? Now, among these two, the shortest burst M is process P2, which is having only two time units. So we need to start with C, and as of now we're completed p1. Ok, fine. Now we are going to start with process P2. Process P2, build random till seven time units. Right? Now at seven time units, process P3 has already arrived fine. Process P1 has also write rate both our edX but p phi has not arrived because it will be having only at time you rotate, but we have reached only till seven, fine. Now among P3 and P4, we need to pick the process with the high having the highest priority. Now, the process with the highest priority is nothing but the process with the least burst ten. Now, process P4, as the lease has, has least burst in combating to process P3. P4 will be scheduled by our scheduling algorithm, and it will run for only one time unit, okay, process P four is also done, will run till late. Fine. Now once, now what I am you rotate all P are both P3s are read as well as painful has also are at right? Now between P3 and P phi v might have to pick the process with the highest priority. And that does nothing but process p for it, since it is having the least burst M comparing to P3. Fine. So P5 will run till time unit ten. Okay? So PFA is also done now we have 1D P3, so there is no other way. We might have to execute process P3. And it will run pin 13 time unit, 13 time units finding. So we are done with the chart. 15. SJF Example 1: Now we can, now we can compute everything, okay, whatever they have asked, like turnaround time, waiting time or whatever, it's easy actually, hereafter. Ok, let's okay, let's first compute something called as completion thing, okay? Completion time of every process. And it is assumed this is process p1, p2, p3, p4, and then p phi c I have right, I have written all the process IDs over here, right, 12345. Now what is the completion time of process P1? Process, process P1 has completed time unit file, right? Fine. Similarly, process P2 has completed at time unit seven rate finding. Process P3 has completed its execution at time unit 13. Process P4 is completed its execution or time NOT. And process P five as computed its execution time unit in fine. So we have computed completion time right now we need to compute something called us turnaround time ago. No turn around ten, we already know the formula. Turnaround time is nothing but turn on time is nothing but completion time of a process minus Arabella time of that progress rate. For example, turnaround time of process P1 is nothing bird completion temp, which is five minus river DEM, which is two. So five minus two is nothing but three. Okay? Similarly for process P2, turnover time is nothing but seven minus three, which is four. Similarly for process P3, this 13 minus six which is seven. Similarly, sorry. Actually for it is seven minus three, which is four, fine. It is 1313 minus four, which is nine. Ok? Similarly for process P4, it is eight minus six, which is two, which means it has spend two time units and say that I have, right? That's what Enron time means. Similarly for process P five, it is ten minus eight, which is two. Ok? So these are that turnaround times. Now we can compute the average turnaround time. How I add all these things for a which is nothing but three plus four plus nine plus two plus two dividend briefing. Okay, this thing, you can compute it by yourself. Okay? Fine. Now, turn around. Time is completely computer fine. Now after donor ONE time, we need to compute something called us waiting time. Right? Now let's compute the waiting time. See one more important point I need to tell here. Here. Actually they didn't do any IO time write for any process. They didn't give any Iwo Tim. Why? Because here they have assumed that it is very important point. Please make a note of it. They have assumed that no process will undergo. I oh, okay. No process is in need of I don't know. Process might have no process needs to read anything from any of the IO device. Okay, that is our assumption for this problem. Ok. It is within the, please write it down. I assume that No process needs I oh, okay, this is this is part of our problem. Fine. Now let's compute the baiting Dempsey may alter. We already know that our turnaround time is nothing but waiting ten plus burst Tang plus iota M. Ok. Now they have clearly given that our IO time is 0. It is 0 now, so turnaround time is nothing but weighting them plus burst time. And from this I can compute our waiting, waiting time equal to turn around time minus burst time. This is the formula for reading Dempsey. Actually this formula's very logical. Ok. you need not the biotech. Okay? Why? See what is meant by waiting time. Actually, in our turnaround, turnaround time is nothing but it is a combination of eating ten plus burst m plus I wrote up. Now I wrote M is 0, so turnaround time is nothing but it is a combination of weighting them, which means the time spent by a process within the RAM without doing anything, plus the time spent by the process with the CPU. Now if you come, if you subtract burst time, which means the execution time from the total time spent by the process in the RAM. You can find out the amount of time spent by the process in the RAM without doing anything productive, which means it is actually waiting to be executed our IO, okay, finally, from this formula, we can compute debating them. Final, let's compute the mating demarcate, baiting them of process P1 is nothing but turnaround time minus burst Emirate. Turnaround time is three and burst time is three. So three minus 3s, 0, ok, similarly, four minus two is 29, minus three is 69, minus three is six phi n, then two minus one minus 12 minus two is 0. Okay? Fine. Three minus three is four, minus two is two. And n minus 362 minus one minus 12 minus two is 0. Fine. Now we can calculate the average waiting time, right? To calculate the average waiting time, just add this all for you, waiting times and then divide it by 0, okay? That is the average waiting time. Fine. Now after average weighting them, we need to compute something known as throughput. Again. Before computing, computing throughput, let's first compute. Sure do lead. Okay. Now what is meant by sheer deal in this and the total time which our scheduling algorithm has showed you with the processes, okay? See, our scheduling algorithm has, has started scheduling processes at time you need to, okay, only from two hour should dealing algorithm has started to ruling processes and scheduling processes until time unit 13, okay? So total shade you live is nothing but completion time of last process minus arrival time of first process. Okay? Should you learn completion time of last process? Minus rM0 came off? First process. Completion time of last process 13 minus arrival time up worst processes too. And so should you lend this 11, okay, this is the shield and see shade you. Length is nothing but total time. Our scheduling algorithm has actually scheduled processes, okay? Our scheduling algorithm, as you deal processors per levered damaged starting Purdue till 13. Now let's compute one more thing which is nothing but throughput. Throughput is nothing but number of processes executed per unit m. Number of processes executed per unit m. C here. How many processes have you executed here? Actually, we have executed five grocers, azurite, p1, p2, p3, p4, and p5, which means we are given only for u processes. So throughput equal to number of processes degraded by shade you length, okay? And number of processes which is completed, xy, completed execution is nothing but phi you. And should you lend this lemon? Ok, so fiber will 5A levered is that throughput, which means phi by 11, processes have completed execution per unit time, okay? The unit is processes freeway 11 processes, fair execution time. Sorry, processes per unit time. Okay. It's not execution TAM, actually it is unit MB. Okay? So this is the throughput. Fine. We are computed everything right? Average turnaround time, waiting time through potentiate your legs. That's it. Okay, this is, this is what all about shortest job for scheduling algorithm, okay, fine. 16. SJF Example 2: So it is exactly like last problem, okay, How we saw, for example, using SJF, we need to find out average turnaround time, average waiting time sheet you'll length and throughput. Okay? Now let's first draw the gunshot. As usual. Our Gantt chart will always start with M in it 0, okay? Start with 10. And one more important point, even for this problem, we need to assume that no process needs. I voted, Okay, no prose, I vote, aim of all the processes are 0. Okay, that is our assumption. Okay, that is very important point. Finally, now, which were a time-honored 0 again, no processes arrive to the queue, right? I know palaces arrow to the ready queue, which means no processes come into the main memory, right? So from 0 to one, that will, CPU will be idle, which means our CPU will not execute any process are executed instruction it'll be, I did. Fine. Now what time is it one, lee process P1 has arrived, right? Process P1 has arrived to the RAM. And so we might have to start process P1 and lead to go till I minute eight. Why? Because we are using non-preemptive scheduling algorithm. It doesn't matter during this time, any other high-priority I apriori processes are aimed to the RAM or not. We will always execute process P1 because it is a non-preemptive scheduling algorithm. Once they have scheduled a process, we will never presume that crosses until completion in non-preemptive scheduling algorithm. Okay, we've seen it already, fine. Now a time you rotate, every processors are able to the ramp, right? Or every process are able to that I am now what we can do among all these preview already completed P1, right? Now among these four processes, the process with the least burst time will be executed next rate. Now the browser the least birthday, which is nothing good process P3. P3 runs per only one term in it until nine are fine. Similarly broad next comes process. P4. P4 will execute for two time units. Fine. P4 is also done. Then we might have to execute process P two, right? Because five is less than 8. So process P2 will execute. Process P2 will execute for 50, ten minutes, and it will so enjoy. It will go till 16 phi. And then really we don't, we don't have any other option. We might have to execute process P five. And P phi will execute till 24 because it needs a time units from the CPU to complete execution. Finally, now let's compute completion time of every process. Okay? Let's compute the completion time of the process. Fine. We already know that completion time from the gunshot itself rate, completion time of process P1 in C, completion time of process P2 is 16. Completion time of process P3 is nine. Completion time of process P4 is 11, and complete name of process P for you is 24. Finally, now let's compute turn around time. Since I'm an ego, time is 0. Since r i o time is 0, turn fine. Turnaround time is nothing but completion. Turn on a dime is nothing but completion time minus arrival time, right? So 8 minus 1 is 7, 16 minus two is 14, 9 minus 3 is 6, 11 minus 4 is 7, 24 minus five is 19. Okay? So this is the turnaround time. Now if you add these five things and if you divide it by file, then we will be getting the average turnaround time rate. You can compute it by yourself. It's quite simple, right? Fine. Now after turnaround time, we have something called us waiting waiting table. Now since our IO team is 0 for every process, waiting time is nothing but turned our own time minus bursting. Okay, turnaround time and is burst time which is 0, there are no ten minutes burst term which is nine, turn around them and as bursting, which is file turnaround time minus burst him, which is again file turnaround time minus burst stem, nothing but 11. Okay? So again, if you add all these five things and if you divide it by five, you will get the average waiting time. Fine. Fine. Now we have computed the average turnaround time, average waiting time. Now we need to compute something called unscheduled length. What's the schedule length? We have started scheduling, which means our scheduling algorithm has started scheduling process at time unit one. And it was xy and inverse, and it was scheduling time unit 24, right? So from one to 24, how much, how many time units we have? 24 minus 1 is 23, right? So she knew length is nothing but 23 fan. Now they're also also has something called us throughput. We know what does throughput rate throughput is nothing but the number of processes executed per unit time, okay? So throughput is nothing bird. Number of processes and number of processor, nothing but phi. Okay, We have only file process as fine dividend, when should you lengthen shady length is 2, there's 23, right? So throughput is nothing but 58, 23. Okay, I think it's quite simple right now. We should be more comfortable with this. Okay, fine.