Operating Systems: Master Operating System Concepts | Lukas Vyhnalek | Skillshare

Operating Systems: Master Operating System Concepts

Lukas Vyhnalek, Microsoft Employee, Programming Teacher

Play Speed
  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x
11 Lessons (45m)
    • 1. Introduction

      1:14
    • 2. What is Operating System

      2:45
    • 3. Von Neumann Architecture

      1:32
    • 4. Monolithic and Microkernel

      4:22
    • 5. What is Process

      0:59
    • 6. Processes Life Cycle

      2:45
    • 7. Scheduler

      3:25
    • 8. Threads

      3:25
    • 9. Processes in UNIX

      6:27
    • 10. Processes in Windows

      11:27
    • 11. Multiprocessing

      6:15

About This Class

Have you ever wondered how is it possible that your computer works?

How is it possible that your application is able to run on multiple devices?

How is it possible that multiple applications can run at the same time?

all of that works because of Operating System.

Save your time by taking this course, in this course, you will learn what is an Operating system, and how it works.

This course should teach you how operating system works, how multitasking works, how scheduling works, what is a process, thread, deadlock and so much more. Also, I am here to guide you, my job does not end by making video lectures. So if you have any questions about anything You can always reach out to me, and mostly I respond within a day.

Another thing I want to mention is that I believe that fast and engaging lectures are better for students, because they keep them concentrated, if you have a slow lectures, students get bored and learns nothing so that is why this course is designed to be fast, I manage to squeeze all the important things into few hours course.

So do you wonder how operating system works? I believe you found the course for you. 

Thanks for your time and I will see you in the course.

Transcripts

1. Introduction: Have you ever wondered how is it possible that your computer works? How is it possible that your application is able to run on multiple devices? All of that works because off operating system Hello, Gas. My name is Luke, and I will be your instructor throughout. Discourage this girls should teach you how operating system works. Are multitasking works how scheduling works, what its process, Fred Deadlock and so much more. Also, I am here to guide you. My job does not end by making video lectures. So if you have any questions about anything, you can always reach out. Me and mostly I respond within a day. Another thing I want to mention is that I believe that fast and engaging lectures are better for students because they keep them concentrated. If you have a slow lecturer, students get bored and learns nothing. So that is why discuss is designed to be fast. I managed to squeeze all the important things into Few are occurs. So do wonder how operating system works. I believe you found occurs for you. Thanks for a time and I will see you in the curse 2. What is Operating System: So what is operating system? Well, operating system serves as a kind of translator or bridge between applications and hardware , so operating system takes care of all the hardware. It makes sure that D hardware is used efficiently, and it allows multiple applications to run at the same time. So that is a lot of work, and it is not easy. Operating systems are very complex and very complicated. So when you turn on your computer first program that start is the operating system. And by starts, I mean it is moved from hard drive into a RAM memory. And then it kind of takes control over your computer so that if you run some application like Web browser operating system, going to make sure that this browser around smoothly and that it has everything it needs to run and how exactly does it work? Well, when you double click on some application operating system, noticed this and it moves this application into RAM memory, and this may take a while. So that is why sometimes when you double click on some application, it takes a while before it opens up right. Well, that is because this program may be pretty big and capping all the necessary files into RAM . Memory can take some time, but eventually Europe will run. And what I mean by run well operating system. Cata tells Processor that this program is loaded somewhere in memory, and he would like Process er to start executing it. And that is when you see some results on screen and winning, for example, need to bring something, Let's say a page. In browser, you press some cool button and browser and then browser tells two operating system. Hey, I would like to bring this file and operating system. That's all the heavy lifting to find the printer sending the data. Basically, it makes sure that your document is printed. So that is pretty much how these simply or part off operating system works where operating system serves as a bridge between hardware and applications. In the following lectures, I will talk about multitasking, and that basically means how is it possible that multiple applications can run at the same time, and I will go into more detail on that topic, so that is pretty much it for dis lecture. I will soon except 3. Von Neumann Architecture: let me start over with for Norman architecture. If you already know what that means, you can go ahead and skip this lecture that if you don't, you should watch this phone. Norman Architecture is the basic model off computer and describes computer as a sequential machine and what that means. Well, instructions are executed one after another. So sequentially the basic structure of computer is here. So here, CPU Central processing unit. And here is where the actual computing is happening. Here is where the code runs. I will refer to it as the process. Er, then there is memory. That means ram memory in your computer and inside his memory is the actual program someone world. And also there is data that program needs and lastly, input output device in order for computer to be able to work with user example off input output device is keyword hard drive, speakers, microphone and so on. And all these continents are connected together. Why are some bus? So this was can a quick explanation off how computer looks inside. If you want to know more about it, just write me a message and I will post another video I made his one really short because I don't want to waste your time and with that being said, I will soon except 4. Monolithic and Microkernel: Okay, guys, welcome to this lecture and this lecture. I will explain what is monolithic and micro kernel. So let's get started. Let me start off by explaining WATERS. Colonel Colonel is a computer program, and it is the core off operating system. Most systems, it is the first program that is loaded, and it handles the rest off start up as well as the input output request from software. So if you right inside your program, something like file open, this will result into system call and Colonel will handle the rest. Colonel also perform scheduling, manages the hardware, and it is handling interrupts Colonel works in protected colonel space and contrast everything. User dust is in user space. So why we have these things separated? Well, for security, if some application can, for example, managed the hardware or scheduling it didn't mean a lot of problems. So dead is by application runs and user space separated from Colonel Space. And if they want something from Colonel, they have to execute a system call like, for example, file open call. So that is pretty much what Colonel s now, let's take a look at the basic architecture off. Colonel first, we have monolithic architecture. So, as I said before, it s kinda connecting hardware and applications. So this all runs and Colonel Space and above d colonel our applications and below ISS hardware. But the important thing is what is in Colonel? When we talk about monolithic kernel, we know that everything is in Colonel. So we have here scheduling into process communication drivers. Where to a file system. Basically, everything is in Colonel, and everything runs in kernel mode, whereas the second architecture is the micro kernel. As the name suggests, this time Colonel is really small. It contains only basic inter process communication tools, scheduler, and we're to a memory and, for example, drivers and server runs in user space. So this time colonel is smaller, and user space is bigger. Now, what do we actually want? Well, that is hard to tell. It depends on what you want. First approach, that is the monolithic kernel is faster because everything is in kernel mode. But there is a tradeoff, since everything is in Colonel at makes the system faster but also unsafe. For example, if there is some driver that is not working, it can cause the whole system to crash, and we don't want that. But still, this approach is used, for example, and Linux operating system. The monolithic kernel is safer because if there is a problem with driver system works, fine. Also. You can, for example, restart server since it runs and user more. But there is a drawback. With speed. Liz model is slower, and in today computer, it is not used so much. Now you may wonder, what do Windows use? Well, it uses a combination off these two, and there is also fourth option, and that is a exile colonel. And that basically means that we have only the most important thing in kernel, and that is a hardware management. But the rest runs in user space. But anyway, that's it for this lecture. Don't worry. If you don't understand some things like what is inter process communication? What is scheduler? I will explain all these terms later on in this cursed 5. What is Process: so what? It's process well, in general, it is a running program. So when you run some app, you create a new process and when closed is that the process will be killed and that's it to operating system. We can run multiple application. So in other words, process er can run multiple process at the same time. Wait, what at the same time? Well, not exactly in the same time, since processor can execute on Lee one instruction at the time. But he's switching between its running processes and he's switching really fast, so it may look like he is running all the processes at the same time, but I will talk more about that later on. The important thing from this lecture is that process ISS application that is running on process er. 6. Processes Life Cycle: it may sound weird by processes have their life cycle. At some point, Brooke says is created, Then he runs, and finally he ends throughout. His life cycle process can be in multiple states, and in here plays an important part operating system because operating system is kind of managing all the processes, since processor can work with only one process at the time operating system decides what process will run and for how long. So here you can see the lifecycle off process. After creation, it goes to Ready state. In this state, it waits until operating system allows him to run. When that happened, process switch to said. Running that means process. ER is executing the process, and now they're free. Possible things that can happen 1st 1 is that processes skilled. So in other words, application is closed that way, process kinda dies. Second possible scenario is that Bro says needs to wait for some input output operation, for example, on hard drive, then operating system decides to Buddhist process into waiting state and process stays in this state until hard drive finishes its operations. Then the Bruces goes back to ready state, and it can be any device. It doesn't have to be hard dry. And the third case that can happen is that for some time the application is not close and the process is not waiting and grown. Any input output device than operating system decides that this process has been a long time on process er and there are other processes that needs to run. So he take this running process and puts it into ready state so that other processes can have a go on process. Er so you can notice that this process, which is jump off operating system applications, actually doesn't even know they are being switched from running to ready state girls operating system stores. All the important data and then there are restored when processes ghost to running state again. So, yeah, that is pretty much how processes and their life cycle looks like. If you don't understand something, feel free to ask and I will soon except 7. Scheduler: the Bard off operating system that the sites What process should run? It's called schedule. This part is pretty complicated because it has to work fast about precise schedule. Er usually use some cuy off waiting processes in combination with priority off days process . Because you need every process to run at some point, you don't want some process to kind of start and wait for process er forever. But you also can treat all the processes the same because, let's face it, some of them are more important than others. For example, system processes are more important than your note. Beth, you can accept that note that is not responding for a vile bod. You would probably get Brenda Matt if your computer would crash all the time. So scheduler has to be fair, it has to use Cebu efficiently. Processor cannot take a break when there are processes that wants to run. Also, there should be minimal response time, so application that user is currently using should have bigger priority that applications on the background. That makes sense, right? This is also called turnaround, and last one is that process er should do maximum amount of work. It get so these are the main things Scheduler should take care off. So in order to do that schedule or use these two strategies 1st 1 ISS round robin and what that means well, process or kinda loops through processes. So processes are in some cycling qui and process er rounds every single one of them so that every process get the Spence, um, constant time on process. Er so this is fair to every process. This strategy treats all the process is the same, but it is actually something that we want. No, we want the more important processes to run before the less important processes. So, Dad is why there is a second strategy and Dellys a priority system. You can think about it as if every process has some number and this is the priority off this process. Then the process with biggest priority gets to spend some time on processor. But because of that sometimes can happen that the low priority processes will never on on process er and that is also bad. So in general, we use combinations of these two so that processes with same priority are assigned to process er using ground Robin strategy. Also, if process waits a long time, it's priority will increase so that it doesn't starve. So, yeah, that is pretty much it for dis lecture. If you have any questions, feel free to ask, and I will soon except 8. Threads: in today's operating system like Windows processor, is not assigned to processes, but it is assigned to threats. Fred is an element that is representing execution off goat off some process, and here comes important fact. One process can have multiple frets, and these rats have their own code. They are executing. They have their own register values and their own calling stack, but they're sharing Graham and every other resource. The fact that we have frets is great, because these switching between France, it's fast, certain switching between processes because we need to change only register values and calling Stack. Also, frets are sharing their resources. So, for example, if two Frets wants to work with same file, the file needs to be loaded on Lee once. Also, it makes the life off programmer easier, because if you have some app that needs to be doing more things at the same time, it is easier to use multiple frets instead of just one. For example, Microsoft word have this thing called out of correct, and this thing can run on background and different Fred so you can ride your content and at the same time, word is correcting you without frets, this would be much more complicated. So threats actually represents execution off gold and process represents memory and shared resource is now let's talk about how frets are implemented. There are two ways how you can get frets 1st 1 is using some library, and the 2nd 1 is that threats are supported in colonel. Both of these options have their pros and counts. If Fred are implemented while library, the operating system sees more Fred It program as a one Fred, it process the bro off. This approach is that switching fret is faster. Also, Application can have a say and scheduling because it is switching frets on its own. So it can, for example, use different algorithm than operating system dust. About the best thing is that these application looks to operating system like one, broke says. So if some Fred is waiting, for example, on some input output device application will be blocked as a process, and all the frets will stop where, on the other hand, support of frets and colonel off operating system is getting rid of the problem. Because operating system sees all the frets. Body switching is a bit slower, but that is a reasonable price for frets independence. So, for example, if one Fred is waiting, for example on input output device, other frats can run on process er so yes, that is pretty much it. If you have any questions, feel free to ask out of rice I will soon except 9. Processes in UNIX: UNIX operating system is used mostly for servers, and they have been around for decades, so there are plenty of versions out there. But in this lecture I will talk more about D. General. How process works on June ICS. As you probably know, Lennox is operating system based on UNIX, and he is using a P. I called post sex. This a p I s candid connecting all UNIX systems. So thanks through this AP, I, you are able to run your applications on most UNIX system. But anyway, let's look at processes state in UNIX processes in units can have nine states. 1st 1 is created that kind of speaks for itself. Process is created, the second state is ready to run in memory and what that means. Well, basically, process is ready to run on processor, and he waits until operating system lets him run. Another state is ready to run, swept out, and what that means is process. ER is ready to run a, but it is not in memory. Next state is sleeping and memory. That means processes may be waiting for some input output device, so operating system tells him to go to sleep until input output device provides response Fifth state is sleeping swapped out So that is the same case as above. But this time process is not in memory. Next state ISS colonel running And that means colonel off operating system is running Next state issues er running. That means this process is now running on process. Er so here is Wendy. Code is actually executed. Next one is preempted and that means process Waas interrupted. There was something important Dad needed time on process er and last state is some be that means process has ended but he's still kind of lifts in operating system. But now the most important thing is how we can switch States and I gathered demonstrated on this picture. So let's say that we are processes and we were just created. So we went to created state then Obviously we want to run on process er so if there is enough memory, we go to state ready to run in memory about if there is not enough memory, we go to state ready to run, swept out where eventually we are able to swap in from this state into ready to run in memory state but sometimes can also happen that we are swept out from memory. But anyway, eventually we get to ready to run in memory state. Now we are waiting until operating system reschedules its qui ones of the time Colonel will run and it will notice us and puts us in its greed. Then we eventually get preempted. So we get to this note and then we run on process. Er so yeah, drink. I'm true that we only have limited time on process er, then we need to leave and make space for other processes. Also, when we run on process, er some system calls or interrupt can happen that way our process is stored and then after interruptus handled or system things done when you get to return to user mode. So eventually we get out off user running state and then we may be done so we can exit. We don't need to compute anything, or we are not done operating system kinds of push us out because it notices that we are waiting on some input output device. So operating system gonna put us to sleep? He basically tells us, Wait here until I get response and since he's Debus in here, we have no other choice. So we get to ST sleeping in memory, and then we can either get risk bonds and wake up and go to ready to run in memory state. Or we can be swept out off memory because we are taking too much space that other processes needs and go to steeping swept out state. And from this state, we eventually go to ready to run, swept out state. So deadest kinda how processes lifts in UNIX. Now let's take a look at how they are created. Processes and UNIX are creating a tree, so every process have its barren and parent is just, bro says, that created this child process. When system is loaded, there's initialized process created and that is a root off this tree. Other processes can be created by cloning existing process, and you can use fork and exact instructions for debt where instruction fork gloans calling process so after call function is returning to two identical processes. Parent and child are then distinguished by returning value to the parent is returned idee off child process and to child is returned zero. Otherwise they are identical and since operating system is trying to safe space goat. And most of the data are shared after clone instruction. Exact kind to replace decode. And that is how new process is created. So, yes, that is pretty much it. In the next lecture, I will talk about scheduling algorithms. So yeah, if you have any questions, feel free to ask end. I will soon exam. 10. Processes in Windows: So let's take a look at processes and windows anti. Let's start with states or frets and Windows. Operating system scheduling is about fret, not about processes, so they're possible. States are right here. 1st 1 is initialized. That means it is created and being initialized. Next one is ready. That means it would like to run, but it waits for scheduler next state ISS sent by. That means fret is ready to run on some process. Er, every process. Er have only one fret in this state, and from this state, you can either go to running state or by preemption. This Fred ends up in Reddick. Wheat preemption is happening when very spread, with high priority that needs to run. Next state is running. That means fret is running on process. ER and the state can end when Derris Brem passion. So once again, front with higher priority wants to Ron than this. Red is switched to stand by or two. Ready Also, threats can leave running state when it runs out of time. It has on process er, then this Fred it's put into ready state. Also, Fred can go from running to waiting, and that is happening. For example, when fret waits on input output device Okay, next state is waiting. That means Fred is waiting for some object. When it is done waiting, Fred goes back to ready state. Or it can also go straight to stand by or running sate. That is happening when it has high priority. That state is transition. That means Fred as its stack outside physical memory. One stack gets back to memory. Fret goes to ready state and last state is terminated. That means Fred is done from this state. It can be re initialized into initialize state. So here is the picture. Dad describes what I just said. So when we initialize new fret we go to Initialize State, then we go to ready State. That means we would love to run on process er but we have to wait. But eventually operating system will pick us for execution. That means we switch into standby state than operating system, can move us back to qui, in other words, into standby state because some more important process needs to run. But if there is no such Fred, we get to process er so our code is being executed now what can happen first thing is that the execution is completed. That means there is no other co to be executed in this fret. So we moved to terminated state and then either die or we can be re initialized and go through this one's again. Next thing that can happen is for example, we are waiting for hard drive. So we are switched into waiting state and then once we get response, we can either go back to running. That happens when we have high priority. Or we can go to Ready State again and we can go straight to Ready State again or we can take it through this transition state. And last thing that can happen when we are in running state is preemption or we run out of time on process er, But either way we get to ready state again or we can also go to stand by state if we have high priority. So yeah, this should be pretty clear. If it is not, feel free to post a question that now let's take a look, get processes creation system. Windows NT is not requiring parent child relation between processes like UNIX system does process is created always by running. Some execute above file or function. Create process creates it, but anti have more subsistence on which process can around. For example, process can run on Win 32 subsystem or post sex that is subsystem from UNIX. So empty a p I is providing functionality and thinks through dysfunctionality we are able to implement all these self systems. The best thing is that anti a PR have no documentation. Yes, that is true. I guess Microsoft didn't have time for dad, but anyway, let's take a look at fret scheduling. So you already know in anti operating system France are scheduled, not processes, but friends. And from that comes one important property. If one process creates nine threats, using create Fred Function and out of Process creates only one Fred. The first process will have 90% of process er for itself. That is, of course, true Onley, when thes frets have same priority because these scheduling is based on priority. But then operating system can a loops fruity frets with same priority, so fret with high priority always comes first, but frets with small priority. Also want some time on process er and operating system can just overlook them or, in other words, let them starve. So they're a capital mechanism that takes care of this problem, and I will talk more about it in a minute. So threats, ransom process er, for one quantum and the length off that quantum varies from operating system that running Fred can be interrupted even before the quantum runs out. Then we are talking about preemption. Also Windows Antaeus supporting multi processing. And because of that, everything that has something called Affinity Mask and that is just a big mask defining on what CPU this fret can run. The default value is that Fred can run on every CPU. But let's get back to scheduling the fact when a friend ISS system or user is not relevant . Once Fred has smaller priority, it ISS reached. But now you might ask Okay, about the burning or scheduling has to also run on processor, right? So what if there is higher priority threat when operating system Fred is scheduling on CPU ? Well, that cannot happen because scheduling is protected, where interruption interruption in computer have higher priority than any other fret so code that runs this interruption cannot be interrupted by some other fret. The only thing that can happen is that interruption with higher priority happens then, yes, but it cannot be interrupted by some Fred. So every interruption have higher priority than every Fred. But now you might ask, OK, but Wendy schedule runts well, scheduler or dispatcher runts when some fret, comes to Ready State or when Fred leaves running state, or when there is a change in priority off some Fred or in after Knitting Mask. So Scheduler sets priority to every threat, and this priority can be from 1 to 31. Why not from zero? Because fret with zero priority is the zero page Fred and what it does well, when CPU have time, it goes from memory and set space we don't use to zero, but then processes from 1 to 15 are user processes, so applications but also part off operating system, for example. The priority of 15 is mostly used for timers so that he has higher priority than any other Fred, and from 16 to 31 are really time friends. These are the critical parts off operating system, and important thing to note is that scheduler never changes the glass off Fred, so it can never happen. That user application Fred has higher priority than 15 about death. Kind of makes sense, right? But now let's actually look how this priority works. Every threat have actually to priority values. 1st 1 is the base priority, and second is current priority base priority or Fred. It's some off priority off process and relative priority of Fred, and the second value is grand priority. And this one can be higher than base priority. So operating system can kind of boost this value. And this boosting can happen on Lee when France have priority from 1 to 15. So here operating system can kind of boost the priority if needed, all the way up to 15. So let's look at the cases when priority is being boosted. The rule is that priority can be boosted to user processes and that current priority must be greater or equal to base priority. So that means operating system priority only increments. It never d crimen. It's under based priority. So Wendy priority changes. First case is when input output operation is finished. Second cases after waiting on event or semaphore. Third cases for example, when Fred Off Process in foreground is done, waiting fourth case is that Fred that is taking care off graphic user interface, wakes up after activity in a window and last gazes that Fred in Ready State hasn't run for a long time. So operating system boost its value so it won't star. So that is pretty much it. If you have any questions, feel free to ask, and I will soon exam. 11. Multiprocessing: as I said before, Windows NT was designed for multi processing. In the real world, that means in computer there can be more processors, and this computer can use same operating system as one process. Er, computer. The reason why we have to stop at symmetric multi processing is that the fact that in computer are more processors heavily influenced these scheduling off France and one process or computer schedule or easily picks one Fred to run. But on computer with multiple processors, this system is not ideal. But the fact is that the real solution Off mortar process scheduler is also not Altimo. Why? Well, because it would be algorithmic Lee so complicated that overall, the optimal system would be slower. So multi process computers are using scheduler. There is some sort of compromise between mathematically optimum motive process scheduler and simple one process. Schedule every process. Have affinity, mask and every thread. Have affinity mask. When Fred is created, the value is copied from process mask. Every fret has then to values. 1st 1 is ideal process. Er, 2nd 1 iss. Last process er ideal processor is process er, where Fred wants to run. This value is set when Fred is created so that frets are spread it into processors and it just loops. So here is an example Imagine that we have four CP use and 12 processes. First process will have first Cebu assigned as optimal. Second, we'll have Second Cebu assigned is optimal Third will have Fert assigned is optimal for will have fourth CPU assigned is optimal and then fifth will have first steep you assigned is optimum and so on So on, so on. So that is how ideal process er iss set and last process er as process er where Fred was executed We keep these value because we want the frets to run on same processors. Why? Well, because process or might remember some data from the time dead this fret waas executed. And thanks to this, we improve the overall performance. Now let's take a look Get how d frets are picked. This algorithm takes place when Fred comes to state ready because then we want the spread to get to state running or at least stand by as soon as possible. So if there is some process, er dad doesn't f any work we assigned to spread to it if there are more processors that doesn't have a running Fred, we big the ideal process. Er, if there is not ideal process or between them, we pick last process. Er, if last process or have also running Fred, we pick any other process. Or that fits the affinity mask. If all the processors that are allowed by affinity Mask have running Fred Operating System tries to Randy Fret using preemption. First he tries Ideal process. Er, then last processor in both. He's trying to replace running and stand by Fred. If any of them have smaller priority, preemption will take place. But if they have bigger priority, this Fred goes back to ready state. So here can happen that Fred with higher priority waits for process er but on some process , er rounds Fred with smaller priority. So yeah, that is a bit of a problem, but it is not that big of a problem, because the probability is pretty small. Now let's take a look at the case where process er is free and we are looking for Fred to run on this process. Er, this situation is happening when the time quantum runs out, so then we are picking some Fred, and we don't care about other processors. So we are picking Fred with highest priority. And DeFrantz, where this processor is denied by affinity mask, are just ignored. The newer operating system are based on this algorithm the differences, for example, that every process, er have its own qui off waving frets. But yeah, that's pretty much it for dis lecture. If you have any questions, feel free to ask, and I will see you next time.