Okay.
I'm gonna go ahead and start recording and we'll get started here.
Okay, good morning.
We are, let's go ahead and get started up.
First off, let's just figure out where we are in context. So, all the. So the tutorials. Are you should be done with them by the end of today.
assignment to is do Thursday.
And then after that, we have the midterm is on the midterms on the following Tuesday and Thursday is the review. So, we don't have basically no more tutorials are coming out until after the midterm.
We're right now, I've covered the material basically that I want to cover for the midterm and now it's really just trying to make sure you know whatever is ambiguous and what's not clear and stuff, I want to talk about.
I'm sure I might have missed something or so.
This is where I want you to ask questions and let's try to go through it so really the difference between today and Thursday is today. I'm going to give you hints and Thursday I will give you more direct answers because I'll put out assignment two solutions.
What is it, what is the penalty deadline for tutorials.
So, the tutorials, have to be in. By the time you correspond turning this falling assignment so everything is do you have to have it in by our by the 14th basically Thursday 10am.
And the reason why you have to everything that I had is because that's what I'm going to give you the solutions for assignment to. Now, if there are extenuating circumstances for you're saying you need more time than you need to talk to me but you have
to convince me that there are real extenuating circumstances. And, and you have to promise me not to look at the solutions because it's not fair to the rest of the class because they will want the solutions to study for the midterm because mid term is
on, you know, the following Tuesday.
So, but really that's why I say you should try to get your tutorials done by the end of today, because that way you have some time to finish up the last assignment.
Anyway, um, so let's go and start talking about. So we have a request for 235 minutes so let's just look at assignment to and see if I can give you some guidelines on on it so let's what strategy should be doing.
So if we read from dev know what data do we get. How can you verify this.
So, I will give you a hint.
No characters, lots of no characters.
Yep. Look at that I just ran for a few seconds I got will how much yeah row 2.4 gigabytes, all zeros, but still.
Um,
so yeah, that's my 3000 capture requires commands to be fully qualified path names.
Um, how can you modify 2000 captures that a command doesn't have a slashing it 3000 capsules searches the current path to find the right program.
My head for this is very simple.
Go look okay this, I believe that it's just a little too tall. There we go.
Sorry I was going
back up here. It's just zoom is putting a little border around my window so I click on tap to try to do other things. Um, let's let's go to
this let's go here, I want to go to tutorial three.
Yeah. So, okay, so what will happen is if it does, it will fill up your disk, then delete it and you'll be fine.
So we'll just say no space left on device. So remove it and you're fine.
I just want to point out so let's, let's try running.
So just to be clear, the way this works to log in here is I have a private key on my local machine, and I have an agent storing the public key. And if I go to got SSH.
There is a directory with authorized keys files, and I can show you my public key because that's not a secret, but this is my public key right here. And so since I've copied that here, the VM knows that I'm allowed to log in and so I can log in without
a password, as long as I files that now one thing one tricky thing to make sure is the SSH directory should only be readable by the user and it's real by anyone else, or things then it'll.
They'll be bad things. So we'll talk more about file permissions later but just a CH mod 700 should do it.
Why I want to do is
get so we've got lecture 10.
So let's get 3000 show.
Now, one thing to understand is literally each tutorial question, each assignment question is based on key concepts from the tutorial or I think sometimes a little bit of new material but it's like, stuff that if you've done the tutorials be like, Oh,
that's pretty straightforward.
So I've got now 3000 show.
So wherever I can type ls here.
Or I can type in LS under it doesn't exact copy of the right program, you know whether I give it the fully qualified name or just give the binary.
And how does it do that. Well, if you look at the code.
There is. So where is the thing where. So let's look at. So prompt loop. So probably loop here, we get an input, we get a string.
And then once you get that you know string that we check to see if it's no, it's no then we exit because that's that basically means end to file and someone hit control D and so our shells should exit, we parse the whatever they typed in, and then we
check specifically special built in commands. And if you have a little background thing that we market as being a background, then otherwise.
We look forward to see whether it was a redirect standard output. And then you know so we do things but then otherwise we call run program, and run program has the argument in the past.
So the path here is, whatever was passed in here and pass came from here, or there's a default path. And, you know, we did the past, you know, get the environment variable here.
So, we did find ends for path.
And so that might have returned no and so we do the run program.
We checked to see how here background, passing it on and basically here we go this program fine binary.
Is it fine to write your own code, do this instead of using the code from the tutorial.
It's fine. But you should understand the code that's in the tutorial because I might just ask something about it.
Here, this is the material.
Here
are certainly mechanisms like it so find binary. And then you go to find binary, what is fine binary do he has this whole thing you give it a pass and things and it searches through the path, you know, and,
you know, so what was what it's doing right now is, this is executing a search through the path was doing is for each of them.
It's a path is basically an array of strings.
And so, it's, you know, going through them and basically looking for. I'm trying try remember how this works.
I'm just trying to like no remember this I can look through this right here walk through it but anyway, this is doing exactly what I want to do if you want me to walk through this I can go through.
I think under path of the default here.
Yeah, a father default that so default default, oh yeah default path is defined in made.
So when you do find them, you pass it default pass because basically if this doesn't return the value, it returns this this is a way that get em is different from find them because find them takes it, the default path, but get them the built in library
doesn't, it'll just give you a no value that you'll have to do and you don't specify the environment it just uses the environment of the process.
Okay so okay I've gotten some requests to kind of walk through the code a little bit so this is.
So at the beginning of. So, this may be a little late but one of the things that you really need to be able to do to do well in this class is read code that is actually one of the key learning outcomes I have for this classes you've been able to read
and understand code of because in practice.
That's what you need to do, that's what you're going to spend most of your time in your work any work environment. If you are at any sort of development type job.
You're going to read much more code, then you're going to write. If you are writing more code than you are reading it, you're doing your job wrong, because you almost certainly gonna be working part of the team building something collaborate with others,
you have to understand what they're doing code is the way programmers communicate with each other, and not just with the computer.
So, and there was a book in the course outline for saying how to read code, give you some tips on how to do this but I mean really, when you're reading up.
Yeah, drawing sketches and you know and GDP, that's a great thing i get i. So, how you understand how you're able to follow code to do things as lots of different ways like GDP is great for having some experiments or you can just stick in print apps.
It's what works for you.
Talk to your Batman action figure,
as opposed to the rubber ducky method. Okay, so but so what is let's talk, you know, you look at each function, what is it doing.
So we're now here in May. So main takes in this stuff from the things like every see program.
This MP is an extra argument don't have to specify you included here or you can always use the global environment thing which you have declares an external, so you get your environment variables, get your command line arguments, the number of command
line arguments, although as you seen this is strictly not necessarily because this is a no terminated array, and you could count to see Mr Dr. But that's part of the API.
We have some defaults. You know, we define variables for username passwords and default ones. We do this little bit of magic to find a signal handler but this isn't actually that magic.
That's, we have us you know we have the address of the single hand or struct which we defined here, we say set it basically set it all to 00 out this, because one of the things is locally defined variables traditionally are not necessarily set to zero,
you define the structure take action, it could have all kinds of garbage in it.
So this basically is making sure that it is all 00.
So I'm going to quit but so how can you genuinely set breakpoints it's 2446 calls, so you get no source, but what you want to do then is start hitting end because interesting enough, it will still go through the lines, it just doesn't know what the lines
are, and eventually you will get to your code, or I think there's a command to like return from the function or something, I forget all the things but neither keep walking through the function until it gets back in your code or unsafe to run basically
to the end of the function, and have it returning then. So, S will
soon.
Yeah, so the key is next.
Will if there's a function call it will run the entire function if you step it will go into the function. So if you're wanting to get to a higher level the color you normally want to hit end because that won't get you further into further functions and
ones that get you back.
Okay so, so what will lay out Asante. So if you go into assembly language I think I forget in GDP there's, you can step through it by assembly language instructions or by source lines.
You probably don't want to step through an assembly language structure if you're curious, you can, but that's, you're probably getting way too detailed yo yo CS continue Yes, the thing you Gordon yeah you've continued, you know there's a bunch but we'll
see we'll continue I think the whole program you just want to go to the end of the function.
And you want to keep stepping through you want to get back to your code.
Yeah, what you you don't submit well so Martin you do, you don't submit the entire program for it but you should have code snippets in your assignment because some of the questions do require you to get pretty detailed answers.
And you can describe it in English, and we potentially didn't give you full credit but it's probably easier just to get the code, because you probably should write the code, but just give the changes as opposed to just dumping all function because the
the reason for I want you to do this is I want you to explain what you did, as opposed to just saying, Here's all this code, you figure out what I changed.
So,
yeah.
That's true. Single every single handle, we are yes through our
last three questions too often so I'm going through the code of tutorial three right now so I'm listening to the code so basically answer with some excessive that the exactly right,
what's the what's the best, best way to explain a change, um, what are you doing typically with the change. You're either inserting code at a certain point where you're modifying code as certain point or deleting some code.
So, you can always make reference to like line numbers, as in, I shall my wiki because those are fixed numbers you know that can be exactly the same, and then say I want to insert or say I'm going to add it to function know when they add to prompt loop
or something but of course not this code you'd be doing it for the assignment code but specify the line number specify the function, you can just be very specific saying like, replace lines, this this with this code.
Is it finally just copy and paste a block from another source Yes, as long as you give credit where it came from, where the, you know where the code came from you should, it's perfectly fine to copy and paste some code from the tutorials and in fact that's
probably the easiest way to solve some of the questions and the assignment.
Yeah, so I will walk through tutorial for an event. I'm going to first going through here now. So let's just so you understand our program first start with name.
We go through here. This is so with this is saying the memory tool is zero. This is now saying that the in the struct, one of the fields in the structure is the is the address of the function.
That is the signal handler. And so we're saying the signal handler function, you know basically that addresses assigned to this handler very struct in here, and then we're saying the flags we're saying we have to say this is a restart.
One of the things, this house is what does MSA restart does.
Does anyone remember what sa restart why you want to do that.
I can
I can I can mention that later when we get to the questions here but.
function. Same thing for Sega, and it fails, it tells us, and then gets the username of the user with a default username if you can find it gets the path with a default password it couldn't get it, and then start to the promises.
And this loop is the one that gets input from the user.
Yeah, sa restarted restarted the interrupted system call Yes, I will explain this in a second year.
If, if you don't have say restart. It's the program, what so if you don't have as much explaining.
If you don't have this line is a restart.
What will happen on a read is, if you get a signal, while you're waiting for input from the user, ie, you printed a prompt and you've done a read, and now you're waiting for the read to return because it's blocked, waiting for the user to type in something.
If you receive a signal in that point, the read will chart we don't waste will return with no data as opposed to restarting, and then waiting for user input.
So what that means is this cause gets hit, because now the read has returned with no data. And we interpret that as end to file. And so the shell will immediately exit Normally, the moment you send a signal.
So that gets kind of annoying. So, we enable as a restart. So basically you know the read when the read returns the user did something as opposed to a single having just mess things up.
So it's not about failing. It's not that this when a single happens not that the system called fail, it's that it's a question of when the system call.
So, when the colonel gets a system called.
Normally the thing will just be
anything a system called that's kind of pending will will terminate.
This is saying okay yeah it's going to terminate run it again. So as I recall, I think this is interpreted by the library
up.
So anyway, so going through, going through this so anyway the prop Loop The Loop, it's just looping through these things and checking to see these things and when in for exit exit thing, pls run p list ampersand set the background flag, and of course
get rid of it because we don't want, we're not going to using that as a pass on to the command, and here this is for redirecting standard out. So part of this manipulation is just getting rid of.
We need to strip out the bracket and the file name. We to remove that. And then,
yeah, and that that's what we're basically copying the arguments to make sure it's like out, and then Reason number of arguments and then, you know, doing that so that's.
And we've set the standard out file name.
So, then we pass it on to run program.
So run program.
Run program now.
What is it doing does a fork.
This is the child.
The parent looks at this
background checks the if the background flag has been set. It has been set. That means, we just, you know, we just say that this is running in the background.
Otherwise we wait. The reason why we do this is because if its background, we're not supposed to wait on it which was a printer prompt, but if it is, it is not about Christ lives in the foreground so we better wait until it finishes.
And so we call the wait system call
other but then the child And meanwhile, it's got to find the binary.
And, yeah, if it doesn't equal know. So you've actually got a file name here, we have to create it otherwise we're going to use whatever file descriptors already there for standard out because know when you have standard instead of outside of there you
don't actually know the file names associated with that they're just open files.
So you don't reopen them because you don't even know their names.
And that's a feature that's using Unix, sometimes.
But we you know we open it and and so we open the file it's going to get opened on a random file descriptor. And we duplicate it so that it now is on file descriptor one.
And then we close the random file descriptors there but I'll still now be open on file descriptor one, which is standard out. So now we've set our processes standard out to be the file specified.
And then we call exactly he can all that succeeds. So, the key thing here for finding the path is this, This we have a command to run, which is the first argument here, but we have to figure out what does that correspond to in terms of binary if this
is a fully qualified path.
Then we are good.
But if it's not, we have to qualify the past by searching through path.
And that's what
that's what fine binary does. So, first way checks is does the name start with a.or a slash dot, it's in the current directory. if it's slashes an absolute path.
We just copy it in return, we're done here, we have to search. So path is here.
path. So what's the format of path path is a string with portions separated by Colin so let's remember, let's.
This is what a path looks like.
So, we're going to have to search basically what's going to try doing is checking to see if each of these directories if we add a slash will add that name onto it doesn't exist.
So we start with, you know, while P is not know so we haven't gotten to the end of the screen, you know, string.
And then we do again, know what we're basically trying to, so this whole loop here is trying to get the, the file name, we're going up to the first next colon.
So this is all extracting say up to here gets that loop. Now again, go through GDP, see what it's doing if you want to watch exactly how this works.
But that's what this is but semantically, that's what this is doing. And then once that's done, You put a slash at the end of it.
So we get like use our BCC tools, we put a slash at the end of it, and then.
Then after the slash.
Then we you know increment our index in there. And then we put name and then we copy it to the end, you know basically to the end there. And then we put a note at the end so at the end of this all this code, what we've done is we've constructed the string.
We've got users are BCC tools, plus the name of the command, plus, plus the name of the plant command, plus an overbite.
This is cc is really annoying for string manipulation.
Because this is you know just now of course there are standard library things for doing a lot of the stuffings drink coffee and stuff here I just wanted to show you if you're actually manipulating the strings you're not using library commands.
This is what you have to do, and this is actually under the hood what's actually happening.
Cuz right strings arrays characters.
Um, anyway so but but all this, we get the file name, and then we just check to see. Does that file thing exist.
If Stop, stop, stop, basically gives us information remember what stopped does.
Man, but they give the same thing. Get file status. What it does is it returns, this structure and the structure tells us all kinds of info about the file like what you know what is we'll be learning more about what all this stuff is.
You're
watching the New World file in a command requires Copy Delete. Well,
there's actually a move command.
There is a way to move a file to another place.
Josh, I think that's a separate thing what what we'll talk about that but this tells us all kinds of information about the file things like, what's his permissions.
But how big is it. Maybe it's just telling us know what was the last access when it was last modified, but it gives us all this info about the file that will be learning about later but the main thing here is if stock doesn't return anything, the file
doesn't exist.
So, here is that return is equal to zero, which means that it succeeded.
So if you look up.
So returned by on success, zero is return on error, minus one is return and Aaron number is set appropriately. So,
if zero is returned, we found it, we found a file that exists, we could, if you want to be fancy or check to make sure it's actually executable. But normally all the files that are in the path, all those directories have only executable files.
So, if you find a file with the right name and one of the directories in the path and it's good. And so, and then if, if we're not the end of the string increment.
Do it again.
So we're just looping through this until we get a file that returns this and if we, If we get to the end of the,
you know, if we don't get anything then we just have, What is this return find binary.
If it doesn't find it in the path.
Just to clarify, are we going through a command character by character identify a slash real question too. Um,
so, okay this is quite, this is a question about assignment to question two so if the other capsule requires commanded fully qualified How can be modified to capture a command doesn't have a slash net
search is the correct path find the right career path and define fleece it doesn't doesn't start
because it has a slash in the middle of it, it won't work.
Yeah, it returns filename. Yes, it does so going back here What does.
Archie Karas this I did not need to copy this. Okay, there we go.
I did not need to copy this. Okay, there we go. Um, I think it returns.
It doesn't return. It doesn't have a return value. So there's that. But there's name.
So it.
So it doesn't copy it their name is a pointer to a string.
Oh, the after this it's copy the file name. So, I think it returns.
Better than was in in out there you're building on fn aren't you, and yeah yeah exactly we're using what basically we've got name here and name is
right but I found it looks like you're actually building the string on fn and that's what you're testing yeah right yeah so then right it's being you're passing it by reference right so you're essentially manipulating right on the, the data that's already
stored that you've passed in. Right, right. What I was just checking to see is if. So this is the file name, this is what there's going to be used by the color because you know we're assuming this is being modified.
Now, I think, if the command doesn't exist if no file exists.
I think what
I think what's happening, then, is we keep the file name the same.
And,
Oh, wait a second. No, no, we're eventually going to get it we're trying to live. Exactly. We're trying to last found file name, even if it doesn't exist.
So it always returns a file name, but then exactly you presumably will just fail, which is kind of.
Well, I guess, you want to give executive, something to run.
Why would it fail if I typed if you type in a command. So, so we can see this actually let's let's let's test this.
So what I'm saying is if I.
So if I do a trace.
Because again, the current directory is not the path. That's why I have to specify it.
So if I type ls.
ls l.
And then this should.
Okay, Now we can look at 3000 shell dot blog.
So if you look at the so we got we don't need that stuff before. So this is the last prompt where we typed it.
So notice. So notice it's doing a stat.
See it's checking everything in. So, this is where it like looking at the system calls what's, some calls watching it checked to see if this exists no expected this exist.
No, no, No, no, no, no these things existed.
And but then the last one, it got what's not been out this.
And it returned that because we got an exact copy of this.
So, you know, fail.
So, no such file or directory. So if you type the user types in a command that doesn't exist. You're going to get that was not sorted, it gives a wrong comparison, it's that.
What happened was is you tried running the command.
It tried it tried starting all these files, none of them exist. That's why it keeps returning no such file or directory. But even though we said no such file or directory, we still doing exactly and exactly also tells us, no such file or directory.
Why is it scan those files in that order.
Because that's the order of them in the path.
Yeah.
Also what happens if you delete one of those files. No No, none of those files exist.
It's trying these are things like the user typed in LSAI. That's not a command. So contrast that with. So if I go further up here, I typed it a successful command.
Where's my LS dissolve loading stuff.
Oh, this is the child sorry.
Yeah, so this so here. So this is where else. So this is it now searching for this so we typed in.
So we did a read the read returned ls that the user types it on the command line. So now we cloned ourselves.
We're now in a child.
The child is 119115.
So now what 914 is waiting for 9115 to finish. 9115 is now doing a bunch of stats.
And most of these are failing no such file factory gnosis files directory, until it gets here.
This stat succeeded. It returned to zero.
So now we do an executive, each of us have been LS, and now from here on out. This is LS code.
This is just it doing LS stuff, 9115 and so we just keep going.
9115 is running doing LS things until we get to 911, so they're exited their weight resumed said 9115 returned. So you got signal sick child, because the child terminated.
We called wait again because, you know, there is no, no child process but that was kind of funny after the weight we get a signal but we'd already called wait so it just resumed.
And then we, you know, get another prompt and we get another command.
Yeah so yeah so yeah it's not in your current directory.
Yeah.
ls command doesn't require a dot slash no in fact if you Type dot slash LS.
That's not gonna work because.so remember, we say, lol. when we say dot dot refers to this.
You changed directory inside a big you're probably right with the dot slash. Exactly.
Exactly.
So.
So where are we so.
So then basically that is all.
You all you know 3000 shell was doing, except for, you know, then the other things that has it has a signal handler for this is for hanging the various signals if you get them.
You know it does something for those. This is the right program that prompt loop, but the other things in here is this P list, and P list.
Is this thing.
it opens this directories proc slash proc prefix or slash profitable
proc prefixes right here.
That's where proc is.
And so we do this. Oh, we can open proc.
And then we just loop through proc, and basically checking out for, he has read you know.
So, this is we do a reader, you're basically getting an entry in a directory. And it checks to see. Does the name that we got for each the entry in the directory, does it start with the digit.
If it does, we do all this, otherwise we skip it. Because if you look at.
There is, you know, numbers here and other things without numbers. These represent prophecies. These do not. So we all want to go through the process.
And then we loop through the,
you know, basically set up calm function. So this is a little helper function basically to get the right name.
We set up calm function so because what is it doing it just copies the prefix.
you know,
PID stir and as ads calm at the end so why do we want calm on the end of the line, because 8976.
Cause it tells us the command, that is running.
And that's the thing we want to print out.
So we get the. So this builds the take the proc p ID, and put calm on the end of it.
And once we have that we open it.
And we read the contents of it to get the command. And then we can print this, so we print the name of it, ie the process number, and the command associated with it.
And if we did not get a command.
If for some reason, we can't you know read that we just put out the name because maybe com doesn't exist.
I actually come does exist for some of them,
does it
know everything has a name.
Yeah, so everything is named that's good.
So, so that's all. This doesn't this shows you how you basically go through a door This is literally, how do I walk through a directory of entries. You read, instead of reading bites in a file you read entries in a directory.
And each time you get a little structure here for doing things and there's all kinds of properties of that you know that you know thing and that's a basically a file name there and you can use that to open things.
Open the file and read what's in the directory. So that's p list. com We saw that. Find binary we walk through that.
Find.
This is again walking through the environment variables and trying to see if an environment match so we say find them. Remember if you type
can be problems here.
Okay do piping.
So this is all the environment variables. Remember this is an array of strings.
So, we have to iterate through that, to find the one that matches.
You know, you know, we have to, you know, so so basically it's splitting on equal sign.
And I forget how my logic of this is so I can walk this but really, again, you shouldn't normally ever be using find out what you should be using as get him, but this is showing you code of how you get environment variables.
So parse arguments again this is part of the arguments, there is much better.
Get off.
Our are.
Get up, parses, but there's no like this is a command line thing.
Where's the thing. Oh.
So here's the thing for parsing command line arguments. Get out.
So just remember that you can do that.
So show you how. So, so there's there's lots of stupid string things here, which is part of yc is such a pain in the butt is like you've got all this stuff and.
Yeah,
sure.
I'm not arguing but it's.
Whenever you look at stuff like that understand. Oh, I'm copying strings so it's going to look messy What am I actually doing and you can protect this another way but actually doing it this way is probably faster because it will be in line so you often
see it. So
are in good shape if you know how to use the library instead of being able to influence ourselves parse arts is kind of confusing.
The main thing though is I want you to understand.
So what I really care about is, Remember, go back to.
I think tutorial to not to go back to tutorial one.
Remember back in tutorial one.
Oh no, where did I show that.
Okay, well, what was it was assignment one, right.
Remember, all the code. So remember this.
Simon one.
Remember these things.
I want you to understand these kind of data structures.
Because this is exactly the data structure that RV, and NPR.
And so if you understand how you would have to manipulate this and why it's structured this way and see.
Really this is even a lower level thing, the idea is that, how am I going to represent an arbitrary number of strings with with minimal, you know I don't have a compiler told me what to do I need a binary format that allows, I can't say it's only about
have five elements or whatever, you could have a number at the beginning, but you might meet the standard way and C is kind of like figure as you go as opposed to knowing where everything is Vance, so this is an array of pointers.
Each of these points two strings, and each of those strings is terminated by a no. And then the array of pointers to strings is also terminated by an old.
So, so you so parse our eggs, is to understand parts of ours properly, you have to understand these data structures.
And that's what I care about you understanding because that this sort of patterns are things that you find a lot in dealing with operating systems for various reasons and
I find that when you have a higher level view of data structures you aren't thinking about implementation issues and when you get to a low level you really have to pay attention these things so stuff like this actually seems really confusing, but when
you understand what's going on underneath you seemed like, Oh, that is a logical solution to the problem they have
is the end of the point array no or appointed to know it's a no character Yes, because it is no is being assigned to a character pointer.
Well, it's technically a no.
I think see interprets this as a no pointer. But again, with the way typing works in its, you would assign no to a pointer.
You can assign a backslash zero to a pointer, unless you cast it.
Yeah. So again, this is so you see this is mean there's all these little bits of 24 one here.
I'm just sort of a.
No, you should have seen this stuff, it's okay to be reminded of it but, you know, this is sort of why expect and you know, and look it up but way. That's why I made this first made this first assignment was like, Can you understand the status structure
and in particular, some of you gave an answer for an assignment one for how to figure out how many entries in this and you use some stuff with using get size and things.
You try to get the size of the array and do you think those are tricks that work at compile time, they would not work at runtime you could not use those things on on RV or MP or stuff like that so
Yeah, that's it, we, if we accept it, you should know how to calculate this dynamically, and the solution solutions for assignment one show you how to do it.
Okay, so going through the questions of.
Where was I here,
compile it.
What happens the input output of the program so you should see that the redirects, you know, the ampersand we talking about, children, children suffering from in the background.
In hip recently basically the cleanest ways you type reset to reset your shell or get rid of the background program.
This is playing with GDP so you can see the system calls
the shuttle was so for output redirection So note that the syntax redirection, you have to put them both, no spaces between them, because they have to be one argument if you put a space that we consider separate arguments.
Yeah.
Why is there a check for P equals minus one is because wait could say there's nothing to wait for, and you saw actually example of that in the code because if we're explicitly waiting.
We'll get the value of the child, but then the process will get these sick child, and then we'll call wait again and go like there's nothing there.
So
make find a binary every attempt show a binary you got to put a printout for the loop may start off with our chasing us once it's on define a signal handler.
We talked about that he starts us get em main thing it doesn't include a default or the whitelist returns no make people as output the process idea of each process, parents, so basically what you have to do is try reading, make some code to read the status
file.
So,
I need to sign this assignment me it's more of an exercise but, you know,
but it's worth it's an exercise worth doing. Yes. So,
nine seven
status, giving all this information on the process. And you can see things like process ID, and the parent process ID worth looking at the end that's what you have to output is you basically have to parse out the outline from here.
What is the XSY just say, you say reboot your machine so
work size is was the exercise worth doing, how to, how to reset reboot your machine. Yeah.
No, you should not need to reboot your machine rebooting your machine is exactly what you should not have to do, you should be able to do it, like, kill the process.
It works, but so if at the end of this class, the only way you know how to fix things is to reboot the entire computer.
You haven't learned the key lessons of this course, because you aren't understanding what's going on and you should be able to fix things.
Not just start over from scratch.
The exercise worth doing here. So how an exercise worth doing is just having to parse the getting the file, you should be able, you should be able to use to just modify that you have that same NP list.
You already are reading com. So you just have to make a new version of setup calm function to set up stop fuck me a startup that function or something that will get the US, a step stop file name, so you get the stat file name instead of slash forward
slash com it'd be status, and then you'd want to read status, but then you have to read, do a read line on it and compare the first couple of characters of the string string compare until it says PP ID, and when it does, then you grab the last characters
and do it I mean it's shouldn't be a hard see coding experience but, you know, it's not strictly necessary for understanding what's going on, but it makes sure that verifies that yeah you could do something.
So that was that one input redirection a standard error.
We already have redirect your standard output reader is just a different file script just copy the code redirection stand out for appeal is the same as the external command.
Here you have to change p list so it takes an argument for the file to open.
You know, the, you know, business gets on the command line arguments with, you know, get that output things so you have to basically have to borrow code from the rest of thing to get that file name of this were to be redirected to, and then you have to
actually open the file and output to it, or you can just open it and just print directly to it.
You don't have to put it on one, but you know what you want to make sure the commands go to that file, and then implement a 3000 Kill Command and what's this data co command.
So here, 3000 killed you should use.
So there's all these killed versions, but you could just do
that process ID signal.
Done.
So, if you went through tutorial three diligently.
Most of assignment to is pretty straightforward. Because look at the.
Let's look at these questions here.
So you've been reading from files is just you know quick little test path names that's there.
This is a little experiment there, which, you know, you should be able to figure out by running it and see what happens if you take it out.
That's pretty easy. How do you fix 3000 calories output to a file specified capture environment variable.
Again, I said redirect output.
Same thing that you didn't tutorial three right there. Um, how many processes, this gets more tutorial for we can talk about that.
What is child exited us for. Why is needed, you know, testing whether you.
I'll talk about that more on Thursday.
How do you create a shell script that says sync term, where our prosperity. Okay, so this is a simple thing.
It has a variable, you can guess the name of the variable, if you looked at what parent process ID number typically is abbreviated bye.
Bye. Yeah.
So I'm searching so
a
reset the machine, the floating IP if you just reboot the machine you'll get the same floating IP address that's defined by the networking infrastructure using something called the HTTP.
Yeah.
Okay. Um,
Can you verify that the shell script from the previous questions actually sending the right single using BFPPF trace.
Again that's tutorial for we want a script that shows signals.
And then here How could you change it. So this one's actually require you to do some writing, but here you're making a single handler, which you've seen already.
You're going to send a signal, which you've already seen late, sleep, which is in the code
in the chart the return value which is in here.
So,
so it's, you know, it's literally This is just an assembling of things. Most under the fuel questions where you have to a little bit of thinking, mostly This is just assembling stuff from the tutorials.
And
when I say exit we return value minus 10. I mean, Yes, exactly. Exit minus 10.
Yes, the assignment is easier than tutorial three definitely be assigned the assignments definitely easier than tutorials, but yeah get get us the tutorials of where you do the real learning the assignments or were you test to see if you actually learn
the stuff you're supposed to learn. If you slack off the tutorials, the assignments hard if you spend time with the tutorials, the assignments easy.
Okay, so those are tutorial for I haven't gone over tutorial for let's go through this.
So, all your so there's this mess of stuff here for getting things set up that was just thing but now.
But now you can just make a new VM.
If you haven't if you haven't gone through this up, but then otherwise we're just playing with these just run these scripts.
But it's like what's going on here with these scripts.
Yeah tutorial three is the hardest tutorial.
That's, but again tutorial three is tutorial three remember is echoing tutorial one.
If you look at tutorial one.
We're talking about a shell, and we had a basic shell and the base, most of the things we took the basic ideas of your personally arguments of are all here in this code.
So, starting with question. Question 11 on in the assignments.
So, I question 11 on if you want to talk to a TA or me specifically I'm happy to give you try you some hints but really the got all these copies now to hit all three.
So go back here.
Go to my.
So if you have a question 11.
But question 11 LN tutorial three okay.
No, no, we're not gonna do bashes source code, we're going to start looking at Colonel stuff.
Ah, so what's the question about scripts in general, what's the difference between a script and the actual program with code, it just that the code in the script can run directly in the shell.
Okay, so.
So, this is the key thing is when we run things like.
So when you when you make this, this is a genuine, the magic here is when you make an executable and you add a line like this, this says, use this as a run this program.
And that program should be given this file as an argument, and it will then it should then running, you know, use this. So, this is right now I shell script because it says bash, but this could be Python, and you can run a Python program, or this could
be the path to know js, and this can be a no no JavaScript program. Any interpreter you want because of this can be BC, and this will be a BC script, any script you want.
This will be there and I think basically the the normal thing is that the you run the interpreter, it's the script and then the rest of the command line arguments i think is what's past them.
That's what they were but this let you know so yeah I got sh is just a naming
This lets you know so yeah I got sh is just a naming de sh is just a naming convention. Exactly. It's just a naming convention, nothing's file extensions don't mean anything to Unix underneath.
Question for tutorial be three I can explain why press Control see to the jury a single DPF trades kills me.
Okay so
control C doesn't work in every case so let's let's let's do run kills me, that's a good thing to do, let's.
Okay, so we're on twice, we've got two windows. Now let's run here pseudo
kills me.
Okay, I am running kill see here, it sitting here running. Now I type ls no kills not being used signals are being sent. Like there was a sick child been there but no one sent it with a with a thing there but let's try doing bc here.
Now let me hit control see
control See, I'm nervous when I hit control see it says interrupt us quick to exit so what happened where was bc sense I noticed that bc was the one sending the signal.
control see just terminated it.
That's interesting. It doesn't seem to generate.
So,
no TTP ID, is this the thread p ID.
So, basically you can have, you have the process ID and actually each process can have multiple threads and each of those can have their own ID so you could have, you know, one of its thread can have received the signal.
So let's just.
We'll talk more towards what we're talking about that for now.
So this is a recording all signals This is recording all kill system calls.
So when you do things because there's more singles going around, it's just not so.
Exactly so top majors handle control see as input, not as a signal. Exactly.
Oh, I know so in user space, if you're.
grocery store.
So kill was
yes exactly kill Yeah exactly, it does so anytime we if we just do a.
Will do.
So it's running in the background.
Kill for.
So, you see here.
So it all is about who sent the signal. It was bash.
So
know this because what we're doing here is
bash has a built in Kill Command that it uses it doesn't always start the command user been kill. But user been killed does exist if we do that we get, that's the fuel Let's run, otherwise bashes the one things oh yeah system the journals and stuff.
So this is system the journal, sending signals.
Oh, I'm sorry.
Right.
Yeah.
Target
is the target
killed as 13 is the safest, which is 13 is that stop.
I think
that, no, no, yeah it is TV is the process here to pee idea target pod. Okay guys so, so we can see here that. So what happens is this process system the journal is sending signals zero to all of these things.
So signal zero is actually signed to check to see what's, what is, it's
okay.
If Sega set to zero, then no single cent but existence and permission checks are still performed. This can be used to check for the existence of a process ID or possibly color is permitted to signal.
So what happens is system the journal is sending signals to all of these processes, and basically saying which ones can it send a signal to, and it's getting a zero for all these, so it can do that and know and minus ones for these, so I can't to these.
Yeah, so.
So one of the reasons why I tried to showing you the man pages as I go was always say like, it's not that I'm just making this information now it's all there.
And you look around at the appropriate commands the, you know, it will tell you how things are working.
One reason I did not.
I've avoided going through this code of the code of tutorial three like explicitly like this was, was hoping most of you have already gone through it and figured it out.
But also I didn't want to go through it until you all had mostly had a chance to try looking at it, because that's a skill you all need to practice. And if I'm just explaining everything and then you're like well why did I have troubles, trying to understand
this code, what was stopping me. So you can identify the skills you need to work on. Because, again, you have lots of, you know, this code isn't very long, and there's lots of things in there and you should be able to navigate fairly easy to understand
how the coding precisely works, what it's trying to do. And then you have the tools to do experiments with which like is that what I actually think the code is doing.
So,
anyway, we've got five more minutes.
Currently as a tutorial for it. So we talked we talked kills. So, kill Snoop says counts that should give you an idea of what I want you to run that to see what system calls are on the system. That should give you more of a holistic view of what's happening.
Bash read line exact needs to approve it's being run, now known exact Snoop also tells you what processes are being created potentially because most of the time when you create a new process.
You're an executable and you can verify this because you can see the process ID.
And if there isn't a process it in between, and there are there are assigned, you know, incrementally, you can be sure you can count how many processes have been created.
Question five co if bash is already running the script what report the first command that you type.
Yeah, it's mid read that that's basically what it is, it's in them.
So, The good comments here yeah look at the code for battery line that's worth but basically what's happening is it's already in the middle of a read, and you're only going to snoop on things at the beginning of the read.
So you have to. It captures it and user space at the when the reason call is done, if, if you're already in the kernel, in the middle of the system call it will catch it.
Sick pipe will kill processes.
So,
so I'm walking you, so I'm trying to, so
I've given you lots of hints here, so things should be, you know, much easier now for a lot of stuff but
that doesn't mean you understand the concepts.
So go ahead and put the answers down, but make sure you understand what's going on because the midterms going to shuffle all these things around, same concepts in slightly different form.
And so if you understand what's going on, you'll be able to do well.
If you don't understand what's going on, you don't have a good mental model that shuffling will completely disrupted and you'll be confused and you will fail.
So, they don't want you to do that. Once you learn this stuff so
I believe that you know it's good for you to struggle for a while and then see what's going on it's like, oh I see the pieces.
How.
Only I can do, I was going to ask the poor me to do a poll real quick.
Okay.
Okay. Please answer this, that we can wrap up.
Okay to throw three questions.
But you have your assignment one marks.
I don't understand how your of your assignment one marks because I haven't computed them assignment.
Yes, I have one has it. It's still being great about it to trial some questions I've been graded but not all of them. So you shouldn't have any grades for assignment one, if you do, that's.
Oh,
yeah.
He was the last liberal before the test. Exactly.
So
that's that's.
I'll check on that that shouldn't be happening so okay let's.
Okay, so this is.
So it looks like 20% of you are feeling good about things.
20% of you are feeling pretty lost. And a lot of you are feeling like tutorial three years, is confusing so.
Okay.