[MUSIC]. Hi, there. We're now starting a new section. We're going to be talking about processes, which is an abstraction provided by the operating system together with the hardware. Just so we can run programs in interesting ways, okay? So then, we're going to see, we're going to start seeing what a process is. Then, we're going to see how we create processes using operating system services. And then, we'll see how we can do interesting things with processes. So, what is a process? And, but first of all, why are we learning about processes? Well, because they're an abstraction of the computer system that provides this interface between the program, and the underlying CPU plus memory. Okay, and this is provided by the operating system. Okay, so what the process have to do with exceptional control flow? Well, the operating system's going to have to use tricks with exceptional control flow to give the illusion that multiple processes are running simultaneously in the system, okay? So what is a program? A program is just a list of instructions, a collection of instructions and data that form your code, that form your software, okay? A processor, obviously, is the piece of hardware that runs these structures in a program. In a process, well a process is an instance of a running program. When you start running a program, you create a process to run the program, therefore the process is an instance of a running program, okay? So, that's a very important idea in Computer Science, and it's not the same as a program or a processor, okay? A processor executes instructions, and a program is a collection of instructions and data. A process is an instance of a program running in a processor, so and they provide two key abstractions. The first one is logical control flow. So, that means that each process has the illusion that it has full control of the CPU as exclusive use of the CPU. Which might actually be in the, in reality the case, but processes give this abstraction to programs that so to processes such that it seems like they have full use of the CPU, okay? And now, the other one is private virtual address space. Means that each, this gives the illusion that each process. Has control over the entire memory. Nobody else is touching memory. Okay, so this is very important because it makes it much easier to isolate programs to manage memory layout and so on, okay? So why are they important? Well, we simplify writing programs a lot because you give the illusion that they have the program, the program has entire memory. And also gives it illusion that it has complete control of the process, or complete use of the process. And how are these illusions maintained? Well, first of all process, process executions are interleaved. That means from the process point of view, which means it's a switch between one process and the other. And the address space is managed by neutral memory by, by the visionary system which is going to be a topic of our next section. So processes can be concurrent. And it means if they run concurrently, if the instruction flows overlap in time. Otherwise, they are sequential. So, let me give you an example. Suppose that I have Process A here, Process A is running, having control in the CPU, then now it's paused for a second. And then it continues running and it ends here, okay? Process B starts here and ends here. Process C starts here, runs, pauses for a bit and ends right there. So, it means that processes that are concurrent are A and B are concurrent, okay? And also A and C, because you see, they are actually running parallel. However, B and C are not concurrent because B ends here right before C starts. now, the user view of concurrent processes as if they are actually running at the same time. Okay, that's the illusion that they have full control of the CPU. When in reality, what's going on is that one, a processor might be paused, but still conceptually executing, but not really. It's not actually making use of the processor. so we can really think of concurrent processes as executing in parallel. Now, how, how does that work? Let's say they have a single process or you have multiple processes running at the same time, how does that work? We need some mechanism that bounces between processes that are running at the same time. So, this is what we call context switching, okay? So, the process are managed by a shared chunk of OS code called the Kernel, okay? And it's important to note that the kernel is not a seperate process, but it's just a piece of code. A special piece of code that runs as part of a user process. But the kernel code has special privileges. So, here's how the context switch happens. Say that Process A is running, and then suddenly it's time-based on a timer. There's a timer interrupt that says okay, the time, processor time for Process A, CPU time for Process A is up. So now, there's an interrupt here, time interrupt, that switches to kernel code. And the kernel code is going to save the state. You save A here, save the state of A. And then you restore B, and then B executes then times up again. The, the kernel code executes through the context switch, and the context switch saves B here and restores the state of A and continue. So that's, that's a process called Context Switch. Now what's actually saved here? What will we have to save here? We have to save the instruction pointer because the we have to know where Process A stopped. So, we need to restore it again and continue allocating from that point. It also needs to save register states, okay? Because we need to restore those to continue executing the program. And the, there are a few other things that also happen there, but that's that's subject for a another time.