 Hey, hi. Welcome to week two. Just a note inspired by this slide. There is a Scientista event today at 4 p.m. I don't know where it is, but I'll send out email about it. So if you're interested in supporting women in CS, and I feel like that's not a super controversial thing to support, like I like women. I like working with women. I would like there to be more women in computer science. I suspect a lot of you guys and girls feel the same way. So come to the tee this afternoon. I'll send email about it after class. Just in case you haven't received enough emails from me recently. OK, so today we're going to finish talking about IPC. And then we'll go on, talk a little bit about file handles. So we'll extend our process model a little bit. At which point, we'll start to talk about the core system called interface that we use to deal with processes. So the kernel is a program. The kernel provides an interface to processes primarily are the most important user of the kernel interface. And at some point later today or early on Wednesday, we'll start talking about some of the core parts of the system called interface that deal with process creation and the process life cycle. OK, a couple of announcements. Today is the ad drop deadline. So if you are, this is your last chance to get out of here without having some sort of weird letter grade on your transcript later in the semester. The recitations are starting this week. Office hours are regular office hours. Schedule starts today. So if you saw the announcement earlier, please look at the scheduled office hours we have for this week. If you can't make at least four, please fill out the form that we sent out and suggest some times that you can make it. Also, if you're interested in us holding weekend or PM office hours, please fill out that form as well. All right. Assignment one is due less than two weeks from today. So it's due a week from Friday. We are intentionally sort of pushing you out the door pretty quickly this semester because we want people to get started. And we want people to get a sense of whether or not this class is a good fit for them. So please start working on assignment one. That's what we're going to talk about in recitation this week. From my contact with people in office hours, it seems like people are making pretty good progress. But of course, that's not an unbiased sample. So all right. Finally, the way that you're going to test, has anyone started using Test 161 for assignment one? OK. Everybody should start figuring out how to use Test 161 locally because it's a really nice way to test things on your machine. And it's a little bit nicer than having to type commands repeatedly into Sys 161. So I would suggest you start figuring out how to use this tool. This is a tool that you can use both locally to test your assignments. And it is the tool that we will use to have you submit your assignments for grading starting at some point this week. So Scott is polishing off some changes to Test 161 that we want to roll out before people start using it heavily this semester. Once that's done, we will release an updated version of Test 161 that you can install, update, upgrade. And then you guys can start using the Test 161 server to actually submit your assignments. That's how you submit the assignments for this class. We'll have more instructions about how to do that. OK. A quick note on partnering. So partners need to work together in this class. The assignments are structured, particularly assignments 2 and assignments 3, are set up with expectations you are working with somebody else. If you're not working with somebody else, you will probably find those assignments to be fairly overwhelming. And a partner is really an important part of completing these assignments successfully. All right. Now, working with other people when you do projects like this is something that you learn how to do with practice like many other things. Certainly, for many of you, I suspect this might be the first time that you're doing something like this in a group where really both people have to participate. I know that you've done group assignments in other classes where it doesn't seem like both people had to participate. I still meet a lot of people with pretty severe emotional scars from 115, 116, where they claim to be the only person that did anything on the project. I think the number of people that claim to be the only person that did anything on the project is much larger than the number of project groups. But clearly, people come away from that experience feeling like no one was helping them and they were very alone. This is not what the experience we want you guys to have for this class. So we're certainly happy to help you guys with sort of dealing with your partner, working together effectively. One thing I would suggest that's very simple is working together, actually physically working together. So setting up time every week to spend time together in office hours or somewhere else, sitting side by side working on the assignments, that's a good way to know that you're both pulling your weight because you're both there. But working effectively with someone on these types of assignments, I would say there's two. Part of this is trying to keep in sync with your partner. And that requires two things. One is the patience to actually let your partner kind of keep up with you. So if you storm off and do the entire assignment in one night before your partner responds to the email that you sent them about when can we meet up, that is not really very effective. Now I know you feel like a superhero while I did the entire assignment, I'm really helping somebody, but you're not helping them because they just lost the chance to learn something and to do the assignment. Now with assignment two and assignment three, that's not really possible anyway. But please don't do that. So you need to pace yourself and you need to come up with a plan with your partner so that they don't feel like you're running off and just doing things. Because that's very demotivating to somebody. Then they think, well, a, they don't want my help, and b, they don't need it. So I'm just going to sit here and do nothing. Now on the other hand, the other side of that coin is being committed to not getting too far behind. So despite last night's epic Super Bowl comeback, typically if you go down 25 points on assignment two and your partner is way ahead, you are not going to be able to come back and tie the game. They just get too far ahead, they're doing too much, they're too embedded in it, and it's difficult to be helpful. So you have to commit to keeping up. So being patient, working together with your partner, and also being willing to keep up and do your part. So those are the kind of two things that'll help you guys stay in sync so that the partnership doesn't get too out of whack. Consider assignment one, your chance to sort of test drive your partnership and work out some of the kinks. So you have like a little bit less than two weeks to do this. We don't form new partner groups in the class. So if your partnership doesn't work out, if the assignment one partnership doesn't work out and you decide that you don't want to work, continue to work with your partner, we will just ask you to not to continue on your own. And your partner will have to do that as well. Otherwise it just gets too messy. Yeah, it doesn't really matter. I mean, in the past, we have some suggestions in the assignments for how to divide up the work. It really depends on the assignment you're working on. For assignment two, there's kind of a natural way to do that. For assignment three, not so much, right? So really, I would say paragraph programming is probably the best way to go period, right? Yeah, well clearly we're gonna continue making you work with that non-existent person for the rest of this semester. No, I mean, if your partner drops the class, that's fine, like you can go on and work alone. So the point is that we don't reform partner groups out of people that may have ended up working independently. We just will allow you to continue working independently and there are modified versions of the assignments for you to submit, yeah. You and your partner are an academic integrity unit, right? Everything that you know your partner should know, everything your partner knows you should know, right? So there is no, you and your partner cannot cheat, right? You can cheat together, but you can't, wait, actually that doesn't make any sense, right? You cannot cheat by telling anything to your partner, right? You can tell them everything, your deepest, darkest secrets, it doesn't matter. You can cheat, your partner can cheat independently from you and you guys will both be in trouble and you can both obviously cheat together, right? But yeah, as far as AI, no boundaries, right? Yeah. Nope, not to the exam, no. It's an important check on the partner system in this class, right? All right, good questions though, yeah. All right, final note today is on grading. So contrary to popular belief, I actually don't have a quota of grades. So actually a couple, like maybe a year ago now, the department made a really serious mistake, which is that they let me have access to all the history of the grades that have ever been given out in the department going back into like 1980 or something like that, right? So I have this huge database somewhere of every grade that every student has ever earned in any class, right? And I did some analysis on this data, it was really interesting, right? It's particularly interesting to look at the grade distribution that different faculty members give out for their courses, because this may surprise you, but nobody tells you what grades to give. No one, like I could give you guys all Fs and nobody, actually if I gave you guys all Fs, you'd probably get so mad that I would get in trouble. However, if I gave you guys all A's, nobody would care, right? It's not like Chun Ming would come in and sing an angry song at me or something like that. You know, it just nothing happens. So I have an unlimited quote of A grades and it turns out, and I'm not gonna name any names here, but very careful, that there have been classes in this department. 400 level classes with several hundred students in where the average GPA was a 4.0, okay? Everybody got an A, and I was looking at that and I just, I was like, is that a bug in my script? Like how can that number be over there on the axis? Like what happened? Anyway, I don't know what happened. Maybe somebody messed up and entered grades in the hub and of course no one's gonna complain, right? Students would be like, excuse me, professor, I think I was supposed to get a C and you gave me an A, there must be a problem. Like that doesn't happen very often. I think I actually, I've had someone say that once, but usually people complain about the other direction. So yeah, so anyway, I can give out an unlimited number of A's and I would actually like to give out as many A's as possible. So my advisor, when I was a PhD student, had this weird phrase, does anyone ever, does anyone say this anymore? Make an A, anyone ever say, I really wanna help you make an A? I actually, when the first time he said that, I was like, that's a really weird turn of phrase. Why doesn't he say what everyone else says? I'm gonna help you get an A. But I like this phrase because get an A kind of implies that I've got some fixed number here. And when I run out, then all I'm gonna be able to give you is a B. Sorry, I just out of A's, you came in a little bit late, all I got B's, and then I'm gonna go to the B minuses, clearly. I got some like raggedy looking C's over there that I can give you too, if that's what you would like. I can make as many A grades as I want. And if you guys make them, if you guys earn them, I will give out as many as you guys earn. I have no problem skewing this class way over to the right side of the grade distribution if you guys earn it. So if you guys earn these grades, there's no downward curve in the class, it's not a problem. All right. All right, final notes for today. And this actually doesn't really apply anymore because you guys never came up in this world. So one of the things that happened last year, this class got a little bit harder because we took away a lot of the free points on the assignments. And you guys don't even really care because no one told you that these free points existed. The only legacy of this is that please do the code reading questions. So the code reading questions are actually there for a purpose. They're not graded, we're not going to make you do them, but if you come to office hours and you're really confused and the TA starts saying, well, did you do this, this and this? And you say, well, I have no idea. The code reading questions are sort of there to start guiding you to the code that you need to understand and to some of the concepts that you need to understand for each assignment. So please do them, even though they are advisory and not graded. Okay, any questions before we go on? Yeah. Yeah, talk to the TAs. Talk to the TAs, talk to other students. I mean, you guys should feel free to discuss the code reading questions with other students. They're not graded, so there's no AI problems here. I mean, I would prefer if you didn't put up a website being like opsclasscodereadingquestions.com and put all the answers, that would bother me. But otherwise, I don't care. They're not graded, so the only reason I caution somebody about posting on the forum is I don't want someone to stumble into it. It's like a spoiler. I mean, if somebody wants to answer the questions to themselves, like don't go up to a student and be like, I know all the code reading questions and here's what they are, right? I mean, if let them find out on their own if they want to, but you can certainly discuss them with the TAs and with each other and stuff like that. I mean, they do have answers and they're not supposed to be particularly complicated. All right. All right, so last time we started talking about the process abstraction and it's a little bit of a difficult task to choose an entry point for a class like this because there's a circularity inherent here with the fact that the processes incorporate these other abstractions and we've started to talk about some things that we haven't really covered in the class yet. So we talked about the things that the process contains. These are other abstractions tied to other parts of the hardware that the computer uses and we'll come back to these in the future. So just sort of like bear with me for a little bit while we get through this. All right. So any questions going back to Friday? So we started talking about the concept of a process with the process abstraction is and we talked a little bit about IPC and how processes on the system can communicate with each other. Any questions about this? Maybe you guys have no idea what happened on Friday. The unbelievable events of last night just totally wiped your brain clear and this is like a new era where everything's gonna go right in the universe. Yeah. Yes. Yeah. I think I have a slide on this in like five slides. Can we come back to it? Actually, well, why don't you ask your question? Sorry, I cut you off before you got there. Yeah. Yeah, absolutely. Yeah. The thread is really an abstraction that's much more tied to the CPU and CPU context and a process includes things like access to files and memory addresses and things like that. So that's completely right and by the end of today or early on Wednesday you should see that sort of come together visually. And I think I have a slide trying to sort of detangle the two concepts. Yeah, that's a good point. Any other questions? Sorry, I didn't mean to cut off the question stream. Yeah. Yeah, I mean, that's a good point. I mean, processes, a process today, I mean, on modern systems, processes can use multiple threads, allowing them to access multiple cores. So the system as time is going along is sharing the CPU both between multiple processes and between multiple threads that can be part of one process or split across multiple processes. Yeah, absolutely. These are good questions. Okay, any other questions? All right, so we're still talking about IPC. Let's just sort of finish up this example. So we talked about kill. We talked about ways to send signals to processes. This is another form of IPC. Processes can essentially register a signal handle that allows them to react to signals in any way they want to. There are conventions with how you react to certain signals that are important. So if I send you SIG term and I ask you to exit, if you choose to respond to that signal by reloading your configuration file, that's not very useful. So typically there are expectations about how these signals work. The super user can send a signal-sending process. This is a common way for people that have administrative privileges on a machine to keep track of things. This is how, if you decide to log in to Timberlake and run study at home or something that computes digits of pi or whatever, hopefully after several days, Ken will notice that there's this weird program that's been eating up all the CPU and will kill it off. And this is how he would do it. He would log in and he would find out what the process ideas and he would send it SIG term and if it didn't shut down at that point he'd probably send it SIG kill. And then you would get an email asking you not to do that again. So this is how that works. All right, yeah, this is one of my, probably my favorite XKCT cartoon of all time, right? Just don't do this on your machine, right? This can be very, very dangerous. People can create lots of problems. This is a classic like error-handling technique people seem to have come up with. It's like, I ran the command and it didn't work. Therefore, rather than reading the output and trying to figure out why, I'll just run it as pseudo and then it'll work. So no, if you run it as pseudo it will cause things to become rude and then nothing will work in the future. But anyway, sometimes this is helpful. Okay, so we'll come back to IPC. You guys are actually gonna implement return codes for assignment two as part of the assignment two when you guys implement the system call interface and this will require you to come up with a semantics for how return codes get passed around from process to process. We'll talk a little bit about pipes either later today or early tomorrow. We talk about fork because part of the semantics of fork are designed to allow shells and other programs to set up pipes properly so that processes can communicate information directly between each other using these shared buffers. And finally, signals are not something we're gonna talk about very much and they're fairly difficult to get right. Carl is very proud of himself. Carl apparently got support for signals to work on OS 161. So you should ask him about that because he's pretty jazzed about it and I have no idea how he did it but I think it's cool that he did it. And then shared memory is another way that two processes can communicate and we'll come back to this when we talk about memory management in a month or so. All right. Processes versus threads. Okay, so coming back to your question what's your name by the way? Noah, thanks. So, and I will try to get this right. So sometimes when we're talking, particularly when we start talking about the CPU it's convenient or it can be tempting to sort of confuse or to swap terminology between threads and process. It'll say a process is running, right? And of course that what that means is that one of the threads that's assigned to that process is running. A thread is really the only thing that they actually run on the system. Now a computing, so this is kind of the way to think about it. The process is this general purpose abstraction that contains a number of other abstractions for multiplexing different parts of the system and the goal of organizing these together is that typically things that run on the system need access to multiple resources. So a typical program needs to be able to compute and needs to be able to store stuff in memory. It probably needs to be able to store stuff on disk maybe and to communicate over the network. So processes give it the ability to do all of these things. Threads on the other hand are really tied to abstracting a CPU. So processes contain at least one and frequently today multiple threads. Every thread belongs to a process. Some threads belong to the kernel but you can really think of the kernel as just again another application, another process that's running on the system that has some special features but it also has threads that can run that can be directly attached to it that it uses to do various things. All right. And again, a process is considered to be running when one or more of its threads is running, yeah. Ooh, that's a great question. I don't think so. I don't know what that would mean. Processes share a thread. Ooh, I'll have to look into that. This is not something that's supported by any of the operating systems I'm familiar with but that doesn't mean that someone hasn't tried it in the past or for some reason. I'm struggling to think of a use case for doing that but there may be something interesting about that. Yeah, let me come back today. Can we post that on the forum? Thanks. What's your name? Michael. Michael. Okay. And part of the other confusion here is that different operating systems will use different terminology, particularly Linux calls everything a task. In Linux both a thread and a process are kind of called a task together. Some tasks kind of represent processes where they have children tasks that are threads that have been created within that task and some don't. So this is even a little bit more confusing. All right, so let's talk, to try to bring this all together, let's talk about a typical process. So remember, process this container that's uniting other abstractions, a process like Firefox and let's think about, or a web browser. I know these slides are really out of date. These slides were written back in the time when I used Firefox because I thought Firefox was awesome and since then now I've become a Chrome user and I say this every year and I don't know. No one thinks it's funny anymore. I guess does anyone know what Firefox is anymore? Okay, some people still use Firefox. Well, I didn't ask you if you used it, I just knew what it was, okay. Whatever, and Firefox is great. I'm not throwing any shade at Firefox. I just don't use it anymore. But let's think about a web browser, okay? My browser Chrome, Firefox, IE, whatever. What is a web browser? Why would a web browser have a thread? I mean, what sort of computation is a web browser doing? What are the threads in a web browser potentially doing? Yeah. Listening for input, waiting for events from the keyboard, waiting for you to type stuff, yeah. Yeah, like waiting for the network. What's that? Yeah, I could have multiple threads associated with each tab. What's one of the biggest things that a browser does? What's that? Running UI scripts. I'm still not hearing the biggest thing. I mean, what is the fundamental task of a web browser? What makes a web browser so awesome? What's that? Oh, the kernel does most of that, yeah. Again, I mean, this is all simple stuff. What's that? This is data, no, come on. I mean, why do you use a web browser? You could just download the file over the internet, look at it. It renders the page, thank you. Yeah, like you don't want to see the HTML source, like has anyone ever tried to use links before? And links actually tries to render stuff, right? Try downloading a web page and just looking at the source and seeing how fulfilling that is, right? See how much excitement you get about the Patriots victory by downloading the ESPN homepage as HTML and viewing that. So it's not really gonna do it for you. The browser renders stuff. The browser takes these pieces of HTML and does this really complicated process where it uses that to produce this graphical display. It's a lot of what it does. It does all these other things you guys mentioned. Core task, rendering stuff, right? You know, loading web pages, blah, blah, blah. Okay, I don't even have the core thing on there. Anyway, I've learned more about web processes. What does Firefox use memory for? Cookies might be on disk, actually, but they could be in memory. Yeah, let's say. Yeah, all the state, right? Like all the, like the actual browser, the rendered DOM, right? I mean, that gets rendered into memory. Web pages don't get stored on disk, typically unless you save an offline copy or something like that. So yeah, I mean, it uses memory to store partial computations as it's rendering things to figure out like probably what's in the frame buffer before it gets written to the graphics display and stuff like that. The code that Firefox is actually running, that is also stored in memory, that's important. All the shared libraries it uses, part of its code base, all the stacks for every thread that's running. Potentially Firefox could be using a bunch of threads, one for each tab, one to, you know, run JavaScript that's associated with the page, whatever. You know, the heap where all the, you know, dynamically allocated stuff gets stored. Okay, what would Firefox, what would Firefox do? Yeah, that. I mean, those engines, right, that's code. So for example, Angular is just a big JavaScript library, right, and same thing with React. I mean, these are libraries that get loaded and then they process the page in some special way to essentially convert whatever those magic tags are to browser compatible markup. So if you go to, there's something magical about React or Angular. If you go to a page that's been rendered with those, what the browser is displaying is still just valid markup. That library just did something weird to the page when it loaded, right? It didn't do the weird thing. It did what it was supposed to do, right? It did what, if you're writing Angular, it did what it allowed you to use HTML elements with random names or whatever, yeah. But those will definitely use memory heavily as they run, right, that's a good question. Okay, Firefox probably stores configuration information, like anything, any of the state that gets saved from iteration, iteration. Now, this may not be as true as much anymore, right? So for example, you know, if you use Firefox, if you use Chrome, if you use other modern web browsers, where does some of this stuff maybe get saved now? Yeah, damn. Yeah, so like my bookmarks, why would I save that locally if there's some sort of service I can use where I can sync it up with the cloud and then suddenly that bookmark is on every copy of Firefox, every copy of Chrome that I'm using on a bunch of different machines. Now of course, where is it saved in the cloud? On some file somewhere, right? I mean, there is some file somewhere in the cloud in some form that contains the data that would normally be in a local file. So it's just on a different computer, but it may not be stored in a file on your computer. And then there's all sorts of like stable data that's stored across different things. There's shared system resources like fonts that could open and stuff like that. Yeah. The plugins we use are... Plugins. Great question. I think those plugins have some sort of data locally as well. I think those plugins, has anyone ever written a plugin for like Chrome or Firefox or is it like JavaScript? Like. Yeah, it's like JavaScript. Okay, yeah. Okay, cool. Yeah, so I think those are just more code, right? But you're probably right. When you install it, it probably saves some code locally and then it has some access to the browser API. I've never written one of these myself, so I don't know exactly how they work, but that's what I would suspect. All right, questions about this. So this is a, and I would encourage you guys to think about other programs that you use. Obviously, browsers are a pretty good one to start with and think again about kind of what, like how do they use different system resources of desktop application? I don't know why people use these anymore, but if you use something like Microsoft Word OpenOffice, you know, like what do those programs do, right? They have multiple threads running. They'll have memory that they're using for various things. They'll have plenty of files open. How do they make, what are they doing with various system resources? And if you want to make this a little bit more modern, you can add the network as well. Yeah, there's a question over here. Stored on disk, but probably loaded into memory, right? Yeah, I mean, a lot of times files are there to store a state that's going to be memory resident, but to allow it to persist across, you know, closing and reopening the browser, right? So, you know, anything that sticks around between browser, you know, I close my browser, I reopen it, you know, what sort of state sticks around. Any sort of caching, you can find those caches, right? Like if you use a Mac, I think they're in like library application support Chrome, and then you can find a directory in there where Chrome has stored in probably some very odd format all sorts of data that it's saved from various web pages. And if you wipe that out carefully, you might be able to get it to force, you know, to force recreate some of that stuff, right? Yeah, I mean, a lot of times these files are not put in places where you're supposed to find them because applications don't want you messing with that data because it can break them, but they're there somewhere. That's a good question. All right, on we go. So, one of the other things I want to try to encourage you guys to do and, you know, feel free to use the Ubuntu environment that you have set up or the Windows 10 environment. Wow, it's pretty cool. That you have set up for running sys161 and test161 to do this, but there are some standard Linux utilities that you can use to find out information about your system. So, one of the cool ones is something called Top. How many people have used Top before? Okay, good. Top shows you information about what's running on the system. So, you might, has anyone ever had that experience where suddenly you realize that the machine fan has come on and like everything's getting slow and you can kind of tell that something is just cranking up and consuming a gob of CPU? Does this happen to people? It's not just me. Yeah, it happens to everyone, right? Top can be a good way to diagnose that because you can fire up Top, tell it to sort things by CPU, and you can see, oh, what's that thing that's running in the background that's consuming 100% of the CPU? Virus.exe or, you know, send all my data to russianhacker.exe or whatever. Now, maybe I want to shut that down. Let's also try on Windows. Windows, the equivalent is kind of a task manager, right? If you control-alt-delete, open the task manager, it will show you similar information. All right, so now let's go back and let's do this example with Bash. Dan, do you have a question? Well, Top is interactive, right? So Top will sit there and like refresh itself, right? PS is a one-time thing, you know? So PS is a command that generates output. Top is doing the same thing. Both PS and Top get their information from the same place. They just format it differently. You know, Top puts together this nice, you know, sort of curses-based UI and then if you let it sit there, it'll update and it'll kind of show you things that are going over in a long period of time. So Top is more of a monitoring tool. PS is something to kind of do a snapshot. Yeah, that's a good question. All right, so let's do this for Bash. What's Bash? Who knows what Bash is? What's Bash? Shell, right? So Shell is a program. Now, Shell is one of those other programs that you guys probably have some sort of mysterious, fairly poorly understood relationship with, right? Because what happens is when you log in to machines like remote machines like Timberlake or the machine that we created for using vagrant and when you open up a terminal, the program that's actually running in there is some type of shell. And Bash is a very common shell. There are other shells. I guess for, I find this mind-boggling annoying but you cannot change your shell on Timberlake because apparently once a day can run some script that changes them all back to the seashell which I don't like. I have no idea why this is done. It just drives you, right? So you can change your shell for 23 hours and 59 minutes, right? And then you can change it back again. You know, I don't know. Anyway, don't get me started. So, but yeah, Bash is a more common shell today. It's kind of the default shell now on a lot of Linux and Ubuntu installations. Bash is a tool for running commands, viewing the output, I mean, it has a purpose but it is what's running, right? When you open terminal or some type of shell. Okay, so again, and Bash is typically running. When you SSH into a machine, what happens is once the SSH daemon has determined that you have the credentials to access that machine, you've entered a password or you set up keys properly or whatever, it launches a shell. And so what you're running in the remote machine is Bash. So this is an example on the old web server for this class. I was logged in, I do a PSA UX, I look for Bash and I find two things. I find the shell and then I find my command that I ran to look for the shell, right? So there's probably a better way to do this, but anyway, there's other commands that you can use to look for programs. I mean, this is something called pgrep which looks through the processes and prints out the process ID of the process that matches. So in this case, 5257 is the ID of the process that I was looking for. This is Bash. And if I run a local PS, if I just run PS without any arguments, it will show me my processes. And in this case, it shows me Bash and PS. Those are the two things we're running at the time. All right, yep, I just, okay. So now we're kind of, let's build up the model of a process. One thing I haven't told you is every process on a system has an ID. The ID, as in many cases when we talk about systems, is a number, not a name. There could probably be many, many copies of Bash running on the system owned by different users or by the same user. The ID allows the operating system to just tell them all apart. So the ID is a number, I think they go up to maybe, I actually don't know what the maximum system ID is anymore. But in this case, the ID that I was able to determine using various ways was 5257. So this is the name of the process for that the operating system uses to identify. Yeah. I think they're just, they typically, the goal here is typically to try to assign IDs so that the likelihood of two processes getting an ID that's the same in a short period of time is very small. So usually what happens is I start from zero, one. Well actually zero and one are special. So I start from a low number and then I just go incrementally. And at some point I hit a maximum and I roll over and then I have to worry about what's still running. So I give out, I don't wanna, but the point is if I, if let's say I give out five to one process and it exited and then I give out five again, there's some processes that rely on the process ID to distinguish between two different processes. And so the process would think, oh, I was talking with process five a minute ago and now there's this other process five and I'm very confused because the other process five is not the same thing that I was, does that make sense? So it's usually I go up incrementally and then once I loop around, I start filling holes. You guys will have a chance to write a PID generator for assignment two. It is a fairly simple, somewhat mind-numbingly dumb piece of code, but it does have to work. All right, so now let's do some other stuff. So let's look a little bit more about what's going on with process number five to five seven. Usually when I run PS on Linux, all I see are processes, not threads. So if a process has multiple threads, a typical PS with the usual arguments will not show me that. However, there are arguments to PS that will show me all of the threads that are assigned to the process. And in this case, I can see, I ran it with those arguments and I can see it still only has one entry. Why is that? What does this tell me about bash? That is maybe obvious if you've used bash before. It's single threaded. It's a shell, it doesn't need 10 threads. Like what is it gonna do in the background, you know? Yeah, so shells are typically single threaded, meaning that when it's sitting there waiting for you to type input, it may not be actually doing anything else. So there's just really no reason for bash to have a bunch of threads running in the background. It only has one thread, yeah. Good question. What happens if you open a bunch of terminals? They run as different processes, yeah. And this is kind of an interesting question because there are two ways to achieve, let's say I wanna set up a web server, for example. One way of, and I want that web server to be able to concurrently handle a bunch of connections. So one way to do it is to start up a bunch of different copies of the web server process. Another way is to have the web server create a bunch of threads internal. And when you look at things like Apache for a while, there were these black magic pieces of code that we were about to figure out, okay, on this machine I should create eight copies of, I should create eight Apache processes and each Apache processor to create like eight threads. So I would end up with 64 different things that could listen for incoming connections. Eight of them were processes and each process had eight threads. So some mixture of processes and threads. In this case when you start up a new terminal or when you log into a new shell using SSH, I just create a new copy of bash, right? Bash is a small program and this is how it's done. All right, good, that's a good question. All right, let's look through the output of this. UUID, where is that? So this gives me quite a bit of information. So this display, UUID shows me the user that the process is running as. Now this is usually the user that started the process, it doesn't have to be, though. If you have certain permissions on Unix systems, you can create processes that run as other users or that run as the root user, which is sort of the super user. I also have things like the process ID. I have the parent process ID. So the parent process ID is the process that created this process and we'll talk about this more later today or early on Wednesday. I have scheduling priorities. I have the size of the image of the process. This is the amount of memory that it's using. The weight channel, so if the process is not running, how many people have some idea of what a weight channel is now? Okay, good, you can start on assignment one. So in this case, the weight, this gives me some idea of what weight channel it's on, what it's locked, waiting for. The total amount of memory it's used, the time, amount of time it's spent running as opposed to waiting. Anyway, so you can see that the operating system exposes a fair amount of information about these processes to you as a user and this gives you some sense of, this is one sort of way to have some visibility into what not the operating system is doing. All right, now if bash had multiple threads, this would show me it doesn't, so I have one thread in bash. So here's my view of bash at this point in this example, see where I'm at. Okay, good. All right, let's keep going. So what would be, I just gave away this answer, what's an example of a program that would have multiple threads? Firefox would definitely have multiple threads, any browser probably has a bunch of threads. But I'm on the web server for this course, so what's an example of a program that would have multiple threads on a web server? Not a trick question, the web server, yeah. Sorry, that didn't make any sense. I'm on the machine that's running the web server, I've logged in the machine that's running the web server. The web server is running on this machine and there it is. There's no time we're using Apache, we don't use Apache anymore, but anyway, so this command, I ran the same command here and I asked it to show me all the threads for this particular process and you can see that Apache has a bunch of different threads. So when Apache has started, it's created a bunch of different threads. If I drew the container for this process, there would be a bunch of different threads that are running inside this process. And this is done because Apache wants to achieve concurrency because every time you download a page from the website, one thread is used to handle that request so that one thread takes your request, figures out what files have to be used, executes any sort of the server side interpreters that need to run, and sends you back the data. And so in order to make sure that somebody else can be simultaneously downloaded in another page from the web server, the web server creates a bunch of threads, all right. Okay, memory mappings. So this gets even more interesting. So this is bash again. These are such cool commands I think, I really like using these. So there's a command called pmap. And pmap will show me all of the memory regions that are being used by this thread. So we're just talking about how a particular process is using the CPU. Here's another core system resource, and I have another tool at my disposal to give me a sense for how that program is using the resource. And we haven't talked about memory yet, but what do you guys, so this is the output of pmap. What do you think these are? OX, sorry, 08048000. These are memory addresses. These are hacks, right? You can sort of tell there's ones that start with B down here. These first three addresses up here, okay? Now if you've looked at file permissions on Linux, you're probably prepared to analyze some of this. Can anyone tell me what's going on here? Like what is this telling me? Anyone want to take a guess, yeah. Yeah, so these are the permissions. So this part of memory, this is a region that starts here, this is the size of it, this is readable and executable, and then it says bin bash, what does that mean? Any guesses? What's that? This is where this part of memory came from. So what is this right here? This region of memory. It's readable and executable. It came from a file called bin bash, and it's about a megabyte. Give or take. Like what is this? This is the bash source code, and I shouldn't say source code, it's the compiled bash binary. So when you build a program, you compile source code into machine code. When you run the program, that machine code gets loaded into memory, and the processor fetches those instructions, interprets them, and executes them. It fetches the amount of memory. Here is where the source code, sorry, the code, the executable code of bash is located. Right here, now this is a little interesting, so this is a 4K region that's read only. It also came from bin bash. What could this be? It's not instructions because it's not marked as executable, so I can't execute code out of this part of memory. What's that? No, it's not a configuration file. Remember, it came from bin bash. It's not bash RC. Bash RC came from somewhere else. This came out of bin bash. Yeah. Yeah, these are read only variables. So these are like constants, like bash has constants, in C you can do pound defines, right? These end up in here. So these are constants that are part of the bash executable, but they're never written to. What about this area? So this, again, came out of bash. It's readable. In this case, it's writable too. It's a little bit bigger. What do you think's in here? Yeah. Global variables that are initialized, but can be changed at runtime. So in C, if you create a global variable and you set a value to it, that variable can be changed, so it needs to be writable, but it has a value that's in the executable file. So when bash gets started, these variables get set to a particular value, and then as the program runs, that value may change. All right, down here, any guesses about what this stuff is? I actually have no idea what this first region is, so just ignore that. Well, actually, I have a hit, but what about this? It's fairly big. It's about two megabytes. It is marked as anon, and it's rewrite. Yeah. Context clues. Heap. Yeah, so anyone use malloc before? Yeah, so this is a part of memory that malloc is managing. That's my guess, my guess, right? All right, so here I have some shared libraries. What's this right here? This is a very common shared library that is used by almost every, if not every C program. It is also known as the C standard library, right? Things like Stirland, all that include U-I-U-N-I-S-T-D dot H, like all that stuff, right? Part of the C standard library. Bash uses the C standard library, like every other program on Earth, and in order to use it, it has to load it into its address space so that code is also there. And then down here, as someone pointed out already, what's this? I have one thread, therefore I have one stack. So this is local variables through the executing thread. All right, I think we are almost out of time again. Okay, any questions about this? So we are, a couple of libraries that have no permission, like they're blank. What is the name of it? Just the last part. I don't know, that's a good question. No clue. I mean, in order for those libraries to be executed, you would think they would need permissions. Come up and show me after class. All right, so on Wednesday we will continue this example. We have office hours now. Rest of the schedule is up. Please fill out the form. They're working on assignment one. It's doing less than two weeks.