 I'd like to start today by talking about this article on Wikipedia we took a look at yesterday in class. Particularly this image here on the right that gives a high-level overview about what an operating system is and what it does. It's that blue box right here that sits in the middle of application software and hardware. You know when you turn the computer on we learned last week that it's just going to fetch, decode and execute all day long. And so if it's not running a program it has to be doing something and that something is the operating system. In fact the operating system manages the hardware and makes it so that all these other applications can run seamlessly at the same time on the computer. Let me take a few notes here in a different window. So let me see, I'll resize this a little bit. So the operating system manages and coordinates hardware resources on all running programs. So when I say hardware resources I'm really talking about the big ones like the CPU, memory, disks, keyboard, mouse, display. There's a lot of fine details of all the little devices on your motherboard and things like that but we're only concerned about the major details in this class. So what I'd like you to do in your notes is go ahead and make yourself a table. I'm going to call this column hardware resource and on the other side of the table I'll say OS component. Now in class Wednesday we're going to talk a lot about the different components of an operating system and what they all do. But let me give you the bird's eye view in this video. Not always like when I'm making tables to make the headers nice and bolded like that. Okay so like I said the main components of a computer we've learned about CPUs. We've learned about memory as well as mass storage. So we'll just call those disks. There's also the display, the monitor or the touch screen that you're dealing with as well as some other devices like the keyboard, mouse, printers and so forth. You can plug in all sorts of things like a webcam into your computer and the operating system ultimately will have to manage that resource. So the components that are in charge of each of these resources are as follows. One of the biggest components of an operating system is the scheduler. That's what decides which program is going to run on which CPU at any given moment of time. And it works together with the dispatcher which is basically a piece of software that switches from one process to another. For RAM we have the memory manager and I'll talk a little bit about that later in the video today. For the disk we have the file manager. Now the file manager is not what you think of as software that you use to manage your files like Windows Explorer or the Finder tool on a Mac. The file manager is what keeps track of which sector on which disk is which file. So all of the behind the scenes details of interacting, loading and storing data to a disk and then giving the illusion that it's just organized with file names and directory names. For the display we have the window manager. That's the piece of software that puts programs in a window and lets you drag windows around the screen like this and resize windows and maximize windows and so forth. And finally for all the other devices we have device drivers. And we're not going to go into a lot of detail about what a device driver does but you should know that a device driver becomes part of the operating system. It basically translates the operating system commands into low level machine language codes for these individual devices and they're all developed by the individual vendors for the most part. So in this video I'd like to talk a little bit more about how the scheduler works and the dispatcher and before doing so I need to explain the concept of a process. I may use the terms program and process interchangeably at times but there is a technical difference. A program is a piece of software that you install on your computer like Google Chrome for example. A process is the activity of running that program. So for example I might open up a new tab and go to my Madison or I might open up a separate tab and go to Google. Of course I spelled it wrong but you get the idea right. And each one of these browser tabs is a separate copy of the Google Chrome program. Each of this is a separate process. Each one of them has a program counter and they have different data, different memory, different things that are being displayed on the page. In fact Google Chrome as a feature if you right click the title bar you can see the task manager. And this shows me not only these three processes but all the other Google Chrome processes I have running on this computer right now. Including like the plug-in for flash or the graphics process, the GPU process. And all of these tabs have a separate set of memory allocated to them. They each have a different percentage time on the CPU. So right now the browser is running 3% of my CPU and the rest of them are idle because I'm not doing anything. They each have a separate process ID. So it's important to distinguish the idea of running a single process of a program but the program itself may consist of multiple processes right. The process is the activity of running the program as opposed to just being a set of instructions that need to be run. Now speaking of having multiple programs running, this is figure 3.6 from the book that shows different time slices of processes that are running. And we have here in this example two processes, process A, process B. You might think of process A as Firefox and process B as your word processor. And these processes are running one at a time. So typically especially if we just assume there's one processor on the computer. Only one program can be fetched, decoding and executing at a time. And so what happens is the operating system allows each program to run for about let's say 5 or 10 milliseconds. And then it's going to let another program run for that same amount of time. The illusion because it's running so fast and so frequently is that all of your programs are running at the same time. But really if you were able to slow down time and observe individual milliseconds as a human being, you'd be able to see the different programs taking turns just really fast. Now this space between the programs, the process switch, is actually the operating system. So what happens is there's a hardware feature called an interrupt which basically causes the CPU to jump into the area of memory where the operating system code is. So in the middle of your program it will jump into the OS. The OS will effectively wake up and see what's going on, which program is running, decide what the next program should be running, do all of the work that the dispatcher does, we'll talk about that in class tomorrow. And then jump to the other process. So here's the picture we were looking at last week of what a computer looks like. We have the CPU on the left, the CPU has a program counter, instruction register, it has a bunch of registers, and then also memory cells for exchanging data back and forth over the bus. So let's add to this picture for this week. In memory, after you boot it up, the operating system is taking up a bunch of cells. And each program that you run in memory as well takes up some memory cells. So I might have process A, or we can call that a program. Let's just put process B here. And let's say that process A is currently running on the computer, right? So the CPU is currently running process A. It might have all these different values in the registers. Of course the program counter is going to be referring to a specific instruction in process A, and then bam, an interrupt happens. So it's time now to jump into the operating system. And the operating system wants to swap process A out of the processor into memory and then put process B back on. This is called a context switch, or the book also refers to it as a process switch. What we basically have to do is save the state of the program. So when the program was interrupted, these were all the values of the registers and this is where the program counter was pointing at. So it's going to take all these values and store them into what's called the process table in the operating system. So here in the process table we've got all the information about A, which is the register values and where the program counter was. And then some other information that we'll look at on Friday, like the process priority, who's the owner of the process, what's the process ID and so forth. And then we can look in that same process table for the entry for B and come through here and restore the state of B. So when B was last interrupted, the program counter was somewhere in B's process and these values might be completely different, right, and so forth. So basically a context switch is taking a snapshot of what was on the CPU, what are all the register values and where was the program currently executing, and then after the operating system makes all those changes to the processor, it can then jump to the program counter and then resume executing process B. Now a lot of the details for this video are in section 3.3 of the book and I would recommend you read that sooner than later. It's only three pages long, but it has a lot of good information in it about how computers actually work and gives you a sense of sort of the details that the operating system handles for you. So please take a read of that before class if you can. If not, I'm sure you'll see it before Friday.