 All right, welcome to operating systems. So let's just dive right into it. Why would you take this course? Or why are you forced to take this course? Because I guess most of you don't have a choice. So why would you take this course? Well, understanding the operating system will make you a better programmer. Because if you ever write software, unless you never write software, in which case, whatever. But most of you will write software. So if you write software, there's only two types of software in the world. You're either going to be writing software that interacts with the operating system, which is like 99% of you. Or if you're not doing that, guess what? You're writing the operating system. So this course is definitely applicable then. So you want to definitely understand how the operating system works. And if you understand how it works, you can understand how to program it for properly. Because I guarantee, well, not guarantee, but most of you probably couldn't explain how Hello World actually works. And by the end of next lecture, well, you'll be able to explain how it works on Linux, at least, in Mac OS, basically. So I'm John A. Alson, your instructor. My last name is a bit of a disaster to pronounce and write. But I will teach you how to remedy both of those. So that looks like a mess. Elf. Elf, pretty simple. Hopefully you can spell elf. I'm really looking forward to winter now, because this room is boiling. And I actually didn't think I would miss winter, but I do. Or at least wish this room had air conditioning. OK, but anyways, elf, good start. That's like halfway there. Elf sin. Elf sin, you can pronounce it like that. Pronouncing my name like Elf sin, perfectly valid. I will not doc you any points for that. That's good, so that's easy. Now, if you want to spell it, just mash them together. Pretty simple. You can spell elf and sin. And then all you have to remember is throw yo after the e. Then you have my last name spelled correctly. Why would you ever need to spell my last name correctly? Well, hopefully you don't, but if you manually go to the course website, all the public resources for this course are going to be there. It's elfsin.com, so you might have to spell it. But there's links to that on Corkus if you don't want to try and spell it. But after that little tutorial, hopefully it's pretty easy to spell it. So yeah, all the lectures, all the links to the labs will be there. And the syllabus is there. All the public stuff will be on that website. We'll use Corkus for links to those and your grades and pretty much nothing else. We have a little crowd mark thing for lab zero, which some of you have already done, because you guys are very good students. And we'll use crowd mark to mark the exams as well. And then other than that, your grades will actually be posted on Corkus, and that's pretty much all we'll use it for. So how this course is structured, hopefully it's slightly modern. So our labs will be the same stuff. If you haven't used GitHub before, you will use it at some point in your software career. So GitLab is just essentially the same thing with a different name that's organized a bit differently and something I don't have to pay for. So that's great. That's pretty much why we're using it. So everything will be done there. There won't be any weird way to submit the labs where you have to submit a zip file and zip your program or whatever where you'll be using Git version control. If you haven't used that, well, that's what part of lab zero gets you used to. And you just upload your changes to the server. And that's it. There's no special submit command. There's nothing no special. You just work as you normally would work as a software engineer. And we will grade your labs. And that's it. Nothing special. So the discussion will be on Discord. Like 70% of you are on it already. If you aren't on it yet, go to elfson.com. There's a link to that in Quarkus too. So that magical URL will present you with an actual Toronto login. So if you log into that, it will also create your GitLab account for you to save you a step there. And it will let you join the Discord server and give you the student role so you can see all the channels and all that fun stuff. And then past that, the lecturers will also be on YouTube. So they'll be recordings there. And they'll be, again, publicly available. And hopefully easy to follow. So even though things are on YouTube and they're streamed, one, things go wrong sometimes in these lecture rooms. And two, lecture attendance is still important. Hopefully you show up. Don't show up if you're sick. I don't really want you here. But otherwise, you should show up because its main reason is it's much faster to get feedback and clarify if anything's unclear, asking questions or anything like that. And also, I can look around the room and you can give me passive feedback. So if I look at your faces and you're confused, that gives me some feedback that what I told you just makes no sense. Today, things probably won't make 100% sense. And that's OK. But aside from that, we'll have some live coding. I'll be able to explain a happy coding accident. So you can feel free to try and break my machine. That is encouraged. If you can break it, you can get, oh no, I'll break some chocolate or something if you break my machine. So that'll be fun. And if there's anything I can do to make attending the lecture is better, let me know. I'm all ears. All right, boring stuff. Evaluation for this course. So you're going to have six labs over, and they're going to be two weeks each. And by looking at this list, you can probably count that there is a lab zero and it goes up to lab six still. And you can probably tell me that, hey, John, that's actually seven labs. What the hell are you trying to pull on me? Well, lab one is mostly set up. So because we only have 12 weeks, we have to start immediately. So I divided lab one into two parts. So lab zero is a setup that you don't need to know anything about the course to do. Most of you, well, some of you have started it. Some of you have finished it. So all you have to do for lab zero is make sure you can actually log into everything. You have to do a one line source code change. Prove you can transfer it to the server. And it is not a hard change. It is your name. So hopefully you know your name. Yeah, don't write my name. And other than that, that's it. And there'll be practical sessions this week. The TAs will be there if you need any help installing your virtual machine. So lab zero, if you haven't looked at it yet, is you're installing your own operating system on a virtual machine. And throughout this lecture, we'll explain a bit what a virtual machine actually is. But I found it kind of weird that you could go through an operating system course and never install a operating system. So this time, you're installing an operating system right away. You'll be installing it from scratch. And it will be your operating system to use for the course. If you break it, well, good thing you learned how to install an operating system so you can just reinstall an operating system. So if you know how to install it, you know how to reinstall it. Then if someone in your family, their computer breaks and they can't afford windows anymore or don't want to, hey, you know how to install Linux because you'll be installing Linux as on your virtual machine. So that'll be great. And also I got the question earlier, all the labs are individual. So most of the labs are new for 3, 4, 4, but I did them in the winter. And mostly the labs are to help you understand the concepts in the course, not try and torture you. So hopefully the labs will be a learning thing and that's why they're individual because hopefully you will learn more about the course by doing the labs. At least that's the intention. And the midterm is scheduled so that it is after reading week because that probably makes the most sense. And for the lab, labs are still two weeks, but because of reading week, one lab will be by the calendar three weeks because reading week thankfully doesn't count for that. So you can use that reading week to study or if you've been keeping up with the course, you can relax and try and have a life during reading week which might be novel to some of you but hopefully you can do something fun on reading week. Okay, so that's the basic breakdown for the course. All right, academic honesty. So you can study together, discuss concepts on Discord, post code on Discord, as long as it's general, don't post anything directly from your lab. Don't be like, here's my entire lab code. It doesn't work, help. That's not very useful. But if you say, hey, my lab code doesn't work because such and such, that's general enough. It applies to the course. People can actually answer that and help you out with that. Yeah. What? Someone posted that, that's just a link there. Yeah, so apparently there's a year Discord that someone posted so you can all join that if you want but the course content will be in the course Discord. Yeah, don't post lab code there. Any other code is fine. Don't cheat. Cheating's bad. It's a lot of paperwork for me. It's a lot of crap for you. Don't copy code. You can go ahead. If you find chat GPT useful, you can try for it. Most of this course is actually reading code and understand what the heck is going on. You can try and use chat GPT to help you explain it, but at least for some of the core concepts of the course, it's wrong. Like it gives really bad answers, even with GPT4. And if you correct it, it'll be like, oh yeah, sorry, I forgot about that. And then it'll spit the right answer, but you have to tell it the right answer first, which is kind of fun. And chat GPT's not going to help you on the exams either, so AI is just a tool like any other tool. Use it, don't use it as a crutch, and that's pretty much the stance on that. All right, so there's some books that complement the lecture. So there's Operating System Three Easy Pieces, which is free, PDFs are free online, so you don't have to pay for it. I won't say, hey, you have to read this. They're just for you if you want an additional viewpoint because the lectures will be different than reading a textbook. So there's that, there's also the C programming language book that you might still have from first year or you had in first year, so this course will be completely in C because all core parts of the Operating System are in C, 99.9% now, so you'll have to use C if you do any kind of low level programming and that's just the way it is and it'll probably be like that for a while because pretty much everything's written in C. So here's some skills you should practice again if needed, so C programming and debugging, very good skills to have because your debugging skills will be put to the test here because things in this course will get weird quick if you, most people's experience is only just having a main and your code starts at main and starts executing from main and that's it. Unfortunately for you that is no longer true for this course and it will be very confusing initially and it might make your brain hurt but at the end of it you will write some very, very, you'll be able to write some good programs and actually understand them. So C programming, pointers, all that stuff you should probably know. Being able to convert between like binary hex and decimal is a good skill to have, less decimal. So if you can just quickly convert hex and binary that's probably good. Some of the things we will have like low level details where that will be useful. Once we get to that point I will show you some like good things to remember to make it a lot easier. So if you just have a basic idea of it now that's fine, you don't have to like drill it so you can do every single conversion in the book but you should at least know what that means. And then little endian, big endian, hopefully you know what that means from computer organization. And then things you should know about memory because memory is one of the weird things that get weird really quick in this course. So what you know about memory now is that hey, there's memory. It is byte addressable, I have lots of it. I get memory addresses from some magical fairy land and I can use them and they're basically pointers. So it's going to get weird fast but luckily for us memory being byte addressable is still true no matter what. So even in this course as well as you know memory is byte addressable, each address is a different byte. You're good, one byte, eight bits, we're all good. Okay, and again at any point please provide some feedback. Course will be challenging so let me know if anything is unclear. Discord seems to really help for this for quick easy question and answers. Don't be afraid to ask. And you can also ask questions that aren't directly related to the course. If you have some type of application, likely it has to interact with the offering system at some point so you can ask what things are doing at the end of even the second lecture you'll be able to closely, more closely inspect programs and figure out what they're actually doing. So yeah, and it doesn't matter what language you write your programs in like JavaScript, Python, whatever they're going to interact with the offering system at some point or another. And again, pretty much guarantee is at the end of the course you will be a better programmer. I will not give you your money back but you can go to the registrar and ask them if you want. So let's get into the content. So an offering system, if you were to say it just has one job it's one job would be that it is managing resources. And other than that, you should never see it. So in APS 105 you've written some programs you of course had Hello World you've written some Sudoku solvers maybe some other things like that. You played with link list. Oh yeah, you should know link list too. So people use link lists all the time so you should brush up on that if you don't know that. And all those applications you wrote that you compiled, those were applications and even though you may not have requested resources explicitly, well if you tried to run it requires a CPU to run on. So you are actually requesting CPU from the operating system. So your operating system is just supposed to manage all the resources. So you can run multiple programs all at once but even if you have a single CPU it's basically your operating system's job to juggle everything and run everything at once and we will figure out how it does that in this course. In the computer organization course you did some assembly and looked at low level hardware how it interacts and all of that fun stuff. This course will have a little bit of assembly you might read but we will read it together so you don't have to go practice assembly or anything like that. But assembly will come up in this course because while the operating system is the thing that interacts with hardware directly not your application and since we're using a modern operating system we're not going to be dealing with the hardware directly. So there's gonna be three core concepts in this course and if there's any three things you need to know about this course these are the three and they also correspond to the three concepts in the operating system three easy pieces. These are the three easy pieces that are not easy. So the first which is like probably 50% of the course is virtualization and the idea behind that is you have one of some type of resource and you mimic or you have multiple things that want to share that one resource. So every one of those multiple things you essentially lie to it and say they have an independent copy of that one resource and your job of virtualization is to make it appear that that's true that that one resource is being shared and everyone is sharing it completely independently. Yep, so resources I mean so it could be any type of resource on your machine. So the first one we'll talk about is like on your CPU there are registers, right? So if you run multiple programs while they each use registers but you don't want them to conflict with each other so they should all think they have their own independent set of registers things like that but like for when you interact with hardware there is no operating system there's no multiple anything so it's a lot easier so you don't have to share registers or anything because you're the only one using them but since we're dealing with a general operating system that's no longer true. So like no one's run an operating system where you can run one program at once, right? You have a web browser open you have some videos open, you have Discord open I don't know, you have other stuff open you can think of whatever you have open so the operating system nowadays has to juggle stuff over and over again and that is the juggling of multiple things at the same time is concurrency so you have to handle multiple programs running at once you have to handle multiple CPU cores on your machine because no one has a single CPU core anymore every machine has multiple cores even if it's your phone and then the last thing and concurrency is when it's going to get real weird so brace for that but again we will make it through concurrency together and then at the end of the course those are the two hard things by the time you run into persistence which is just storing data consistently even if there's a power outage or something like that by the time we get to persistency that will be easy and the course will pretty much be done by then and you don't have to worry about it alright so here is a quote that I had in my fourth year that is shockingly true so here it is if you haven't heard it yet in third year so all problems in computer science can be solved by another layer of indirection so instead of solving the problem you just generalize it and then you solve that problem and then you try and map it onto whatever the real problem is so one of our first abstractions in this course is going to be something called a process so we can have some vocabulary to talk about when things get really weird so what you're used to before is having a program so whenever you had your C code, you compiled it it created an executable we're going to call that a program so it is just a file that you can execute so that file, if you know what to look into for the file and how to understand that file which we will a bit next lecture it just kind of tells the operating system a bunch of stuff that you will not understand yet and it also contains like all the instructions so like all your assembly instructions but in binary and all the data it requires to run so it's just a file that is sitting on your machine so whenever you try to run that file or execute it the operating system will turn it into a process when it runs it so a process is just an instance of that running program so if you have Hello World, you can run it then you can run it as many times as you want you can keep going launching Hello World, Hello World, Hello World so each time you launch Hello World that would create a new process and all of those processes are running the same program so we already kind of talked about it already what would be required for something like a process so a process, well, it's going to execute instructions so it's going to use registers if we had two different processes fighting over registers that would not be good so in order to solve the problem well, in operating systems course your one of your solutions that will probably work is like, hey, let's just virtualize it and that will probably solve the problem so instead of having each process use the bare physical registers on the machine and not doing anything about it the operating system is going to create virtual registers so each process has its own independent set of registers so whatever your program isn't running and the operating system comes back to it your registers are the same values they were when you left off nothing changed under the hood nothing messed with your program it runs the same way every time and that is great programs also use memory so they'll also, you know, you have a stack hopefully you learn an organization kind of what the stack is so your program will use memory it'll use a stack and it'll use a heap so this will be my first question to you is, well, if that is true and I have physical memory on my machine how can I run two different programs at the same time? so say I had Hello World and then another program that just counted how would I run them at the same time? yeah, yeah, so one of the answers is concurrency is an issue because the operating system is going to have to juggle between them so, sorry, let me clarify so in terms of memory, how are their stack let's just say their stack so how should the operating system deal with each process's stack? yeah, okay, so the answer is hey, the operating system just uses physical memory directly so the operating system probably knows what memory is in use, right? so if a process starts it can give one process some memory for its stack and then another process some memory for its stack and then everything's fine everyone agree with that? no? anyone disagree with that? or think of any issues with that? yeah, yeah, well that's one issue that might pop up is what if, you know, you have one stack here one stack here and this process uses a lot of memory and it starts creeping up into the other one and then it kind of overwrites its stack that's probably not good that's definitely a giant issue any other issues we can think of? that's a pretty bad issue oh, yeah so I cannot hear you okay, I wouldn't hear that closer yeah, so two processes using the same stack one, that would be bad so the two requests could come in at the exact same time which goes back to the concurrency thing and it could just give both processes the same stack in which case that would also be very bad so that's another thing that could happen so other than that, that could work you could think the operating system is like somewhat magical and it can know that hey, if this process is using too much space well, I'll just go ahead and kill it and that's a technical term for this course we'll have in about lecture, like six we're gonna have some gruesome terms in this course but they're like the correct ones it's really weird your Google searches are gonna get so weird for this course and you'll know what I'm talking about soon so the operating system could magically know how much it's using and then if it's using too much instead of overwriting another process of stack it could just kill it or something like that that might be okay any other issues we can think of those are still pretty bad ones because that thinks the operating system's fairly magical which it's not really yep, yeah, if there's not enough physical memory for the stack, that's bad that's an issue that you're gonna have to deal with anyways right, if you're the operating system we'll see what we do with that but the answer isn't terribly surprising is you just kill the thing that's using the most memory alright, so what about global variables? they would be really weird although, so this'll kind of explain how global variables work cause probably no one knows what the compiler actually does for global variables so because that program is just a file and it has to explain everything ahead of time well, any global variables you use in that program when the compiler actually compiles it and creates that program it has to know what memory address to use for the global variable ahead of time so it has to know that, hey if I have inX that's a global that's address 1000 or something like that so if this was the case and you had just physical memory well in order for this to work it gets really really weird because the compiler needs to know what address to pick you could have a solution to that which is kind of bad which is just like have a global registry of every address every possible physical memory address and say, okay your Hello World program you can use addresses 1000 to 2000 some other counting program can use 2000 to 3000 Chrome can use 3000 to 5000 Firefox can use 5000 to 6000 something like that and that would I guess kind of work but does anyone see any glaring issues with that? Yep so you'd have to declare it like ahead of time so you could run into the issue of space where like, hey I'm address somewhere in like five gigabytes or something like that but my physical machine only has four and then suddenly your address doesn't exist so that would definitely be one bad issue any other big drawbacks we would have if we did that? Yes, you would need a registry for every program in existence also if you ran two of the same program at the same time that would also be really bad because they would both have the same global variable and both programs which are supposed to be different would be using that same global so that would cause a mess and also another big drawback is well it would have to be every program in existence would have to register which isn't going to happen and also if a program isn't running that has a registered address well no one else can use that memory because someone else might launch that program at some time in the future so it's just gonna waste all the memory clearly that's not a thing you can do so knowing our essentially one solution what should we do with memory? Yeah we should just have something called virtual memory for each process so if each process has its own virtual memory that means each process has its own independent view of memory and thinks it can use all the memory it can so if you have a global variable the compiler all it has to do is pick any old address at once and it's the operating system's job to figure out how to make it map to physical memory and if you have virtual memory you can also run two of the same process at the same time because even if they use the same memory address well it will not actually be the real same physical address so that will be okay your processes can all operate independently and that's kind of the nice world you've been living in already so in APS 105 when you wrote it guess what your program was using virtual memory and all the addresses if you printed them out they weren't physical addresses they were actually virtual addresses and one of the hardest things in this course is actually doing the mapping of virtual to physical and that will take us like a full week to do but we can think of it so yeah here is that bad memory layout of just having a big global registry and then different processes need different programs would probably need more too so if there's a big global registry how do you argue how much memory your program actually needs and then if you want to change it it's a whole mess and just a disaster just use virtual memory that's our solution so let's do some experiments so now if we have two processes that run the same program well because there's virtual registers and virtual memory it should work no problem so let's look at this program so this program here let's switch to all right so let's look at this program so this program just declares a global variable I was very creative I called it global and it is just an integer and I put static in front of it most does anyone know what static actually means yeah yeah so technical terms it's only visible to that translation unit it's used for different things if I had something that might not mean something to some of you but funnily enough these two things are very different use of static this static just means I can only use this global variable in the C file if I try and use it in another C file I won't be allowed to so it kind of reduces the scope of your global variables which makes it a bit different and that's the only thing that static does if you just stick it in front of a global variable it does a different thing if it's in a function it will make that variable outlive the function so if in here you know you looked at the value of x here and you incremented it whatever the first time you call the function here x would be zero then the next time you call it it would be one and then two and then it would increment every time and it would persist across function calls all right that was a weird C thing you don't have to know that that's not terribly important you might use the static global variable thing anyway sorry back on track so main hopefully you know what main is this should be familiar if this is not familiar I don't know what to say so it main should make sense so next thing we'll do we'll declare a local variable an integer again I'm super creative I will call it local and then I will have a while loop that says while one so this loop will just happen over and over and over again I will increment local inclement global and then I will just print them out and then sleep for one second what that will do is tell the operating system hey put this process to sleep like don't execute it for at least a second and then after a second you can go ahead and execute it again so this should count up both variables once every second so if I do that counts up as you would expect so I can switch over to a different terminal oops and I can run another process so now two of them are running at the same time and they are completely independent so this is counting up let's see we are at 10 and if we switch back to the other one it's at 20 and they're not interfering with each other so this one's now at 25 if I look back at the other one it's at 17 it's just counting on independently in the background so this is only possible because each of them are completely separated and independent of each other it wouldn't matter if I you know ran it waited for it to finish ran it again or if I ran them both at the same time doesn't matter they're going to behave exactly the same the only difference between them is running them at the same time as you might imagine might be a little bit harder for the operating system but again this is now our problem so the yeah so any questions about that so they both seem to be fairly independent of each other alright well let's do something so slightly crazy then so we can do a little experiment because we love pointers so to compare and see how right we are which spoiler alert this won't actually tell us that much let's just print their addresses so it could be the case where both their addresses between the two processes are the same for the global or the same for the local it actually kind of depends on the underlying operating system and what options you have installed which we'll get into later but let's go ahead and recompile and run that we got two addresses we'll go here run that got two addresses and now we'll compare them so the first time the local variable well that would be on the stack and it got this address that ended in 36 AC now if we look at the other process its local variable on the stack was 2D 0C so they could have been the same address but for some reason our operating system just gave them different virtual addresses for their stack that is actually a security measure if you go way back in time when people cared about security less those addresses would actually be the same between both processes but now we know that hey that's okay because their virtual addresses they're not real we can look at the global two it's a bit more fun but it should be different so it ends in 044 and on this one it also ends in 044 so they look actually kind of similar but this one has 420 before that haha and this one has CD6 so they're actually different but they look kind of similar again this will be a security measure before if I ran this with the correct security options they would have actually been the same virtual address both of the global variables and this would have hopefully made more sense so there's nothing saying that they couldn't be the same address so what we find well we found that they're different between the two processes but they didn't necessarily have to be because of virtual memory but you'd be forgiven if you just looked at the different global or different local addresses and saying that hey the operating system could just give each process physical memory for each of their stacks and it would have been fine the global addresses were the same you would have known that would have been possible because the value didn't change between them they were always in sync so can we think of what else might be needed for a process well that seemed good enough for now that's all we need for a process so our process oh sorry yep sort of so the question is is the virtual memory size the same as the physical memory size for each process and the answer to that is no so because virtual memory is fake and we'll later discover how you can do the mapping of virtual to physical but once we get into it you can map any virtual address to any physical address if you want so they don't have to line up so you could try and access address 20 terabytes or something like that and the operating system could make that valid and then if you only have 16 gigs of RAM it would be some valid memory between there so it doesn't necessarily have to line up so that's also good because if it had to line up whatever you compile your program you need to know how much virtual memory your machine has and that's not really a thing because you just have a executable and you distribute it and you don't know what computer someone's going to run it on right or between running it I could I could shut it down I could rip out a stick of RAM and run it again right and now I have half the memory so our process is going to look something like this this is enough to understand a process for now it will have virtual registers because it's sharing the CPU between different processes so they shouldn't interfere with each other again you want things to be independent generally virtual making it virtual is the solution so each process gets its own virtual registers to take care of the CPU and then it would also have its own virtual memory to make sure that you know they actually share memory and don't interfere with each other so the stack and the heap would be part of virtual memory and all the addresses you would have would be virtual addresses and this is the same thing for like your virtual machine so your virtual machine while you're going to be installing another operating system on your machine what's a virtual machine it's just creates the illusion of another machine so your one physical machine in this case my laptop can run two operating systems at once so one physical machine if I want to run multiple operating systems I just say hey let's make a virtual an entire virtual machine virtualize literally everything and then you install an operating system on top of that virtual machine and as far as the operating system is concerned it has control over the entire machine so the virtual machine you install your operating system from its point of view it's going to think it has complete control over the machine which isn't really true because hey it's a virtual machine and you will use virtual machines in your software career if you ever use AI or anything like that or any web servers they're all virtual machines so here's some more example code from this class we can go over so once you sign up and get the email from get lab you will have access to this materials directory which or repository which has all the lecture code and the lectures themselves if you want compile them if you're crazy if you don't want the pdfs on why but this is a clickable link so you can look at the pds click the link it'll take you to the repository and i put in discord steps to how to get the repository on your virtual machine just in case uh... should post those as well but once you're in the materials directory you can just cd into whatever lecture we're at and then the next two commands are going to be the same all the time they're going to be mason set up build which will create a build directory for you and set up your compiler and do all that so you might have seen make before so this is instead of using make we're using me son which is an actually readable build system if if you ever have been if you ever had to write a make file i'm sorry uh... mason is a lot better for that for being readable and actually doing things that supposed to do uh... then after that you run mason compile and point to the build directory and it'll compile and whenever you want to recompile your code you just re-type this mason compile again and it'll recompile your code and in fact i did that earlier this is going to be a read for bytes example and this will be kind of an example of what code looks like in this course some of it will be familiar but some of it don't worry if you don't can't read it so again you'll start with main main will have some arguments hopefully you know what those arguments are so this is a number argc is the number of arguments in this argv array and argv is an array of pointers to characters throughout the course a pointer to a character sometimes i'll just say that's a string sometimes i'll say that's a c-string for this course they mean the same thing so char star i'll probably just say string or c-string if i want to be super technical about it this if statement you should also know about it no no so the question was will i need to know how to learn how to write mason the answer to that is no but you can open up the file and it's actually readable you'll have some provided starter code where you don't have to do anything you never have to modify it at all in fact if you modify it you will probably break the marking stuff so it's mostly for you to read and if you want to start your own project i would suggest looking at those for some examples okay so here it checks an if statement that checks the number of arguments passed in make sure it's two if it's not two it returns from main which exits the process or quits the program or however it was referred to you before course if we're being technical main returning from main will eventually exit the process so it will end the process and it will stop executing all right so hands up if you have had to read or write files before in c we have a smattering about half of you so hands up if you use f open so it's c++ count it's c++ kind of counts but not really yeah so if you used uh c++ or if you see you probably use you might have used f open don't worry if you haven't used it before we're going to learn how to interact with files and stuff in this course but you might have seen f open in linux we are going to pretty much use exactly what the operating system expects so we're not going to like sure coat any function calls to the operating system we're going to use as close to possible the actual real ones that happen so we're not going to use f open we're going to use something called open so the reason that f open exist is because it is in the standard c library and the standard c library is trying to abstract files from you so that you can use f open no matter if you're using windows macOS linux whatever f open will work but open will only work on linux and macOS because of that specific operating system so since we're getting specific in this course we're going to use something called like open this will open a file and this argument here this are read only just opens it for reading because you have to tell the operating system what you want to do with the file for you know just so it can double check you and if you use f open you've got a file pointer back in linux you get a number back file closed like what are these so these are just the names of the arguments yeah so i have a plug-in that says so this function takes two arguments the first one's called file and this is the actual argument i'm passing so just go ahead and give you names for argument so it makes it a bit easier to read hopefully and if you follow the lab setup guide you'll get this as well alright so the next thing this does so it opens a file and gives you a number back and then you have to do everything based off that number you don't have to worry about understanding that for now but you should know what uh... array of characters is so this is an array of four characters arrays will be important as well then you'll have this function called read which is telling the operating system hey i want to use this file descriptor to read and it will actually the operating system will write values into that character array for you starting at whatever address you give it so it will start at the beginning of buffer and then right up to size of buffer which would be four bytes so it would write up to four bytes then we have some error code that we don't have to check and then it will return the number of bytes the operating system actually read and then this for loop just loops over each of those bytes and since it's asking if you know what asking for encoding for strings is it will see check the value of the bytes and knowing what numbers correspond to what characters it'll check if it can print it as a character if it can it'll print it as a character if not it will print it as a hex value so with that we can run it and know that things are magical and i have to do this really fast so i can have it read itself and it will look something like this which will be really weird there'd be like a weird hex value and then ELF i swear this has nothing to do with me this is the file format for any executable on a links machine or playstation it will be this format every executable will start with this if you write hello world and see it will start with this uh... so i will quickly quickly go here this is hello world this is the simplest hello world you will get it is in binary and if you run that read the first four bytes of it it will also be seven f and then ELF and then if you actually execute this program it will print hello world so a fun thing you can do is go ahead compile hello world in c tell me how big it is and compare it to the size of this and you can also run that read four bytes on your hello world c it will start with that ELF and we can compare and we'll go over this next lecture so just remember pulling for you