WEBVTT 1 00:00:21.000 --> 00:00:28.020 William Cheng: Good morning. If you have question can go ahead and ask, because the session is recorded, so everybody else can, you know, watch it later. 2 00:00:49.620 --> 00:00:51.180 Jiaming Xu: hypervisor amass a question. 3 00:00:51.450 --> 00:00:52.230 William Cheng: Sure, go ahead. 4 00:00:53.130 --> 00:00:56.460 Jiaming Xu: So in the side 5058 5 00:00:56.700 --> 00:00:58.290 William Cheng: Okay, so let me let me go there first. 6 00:00:59.310 --> 00:00:59.940 William Cheng: Slide 7 00:01:14.670 --> 00:01:16.080 William Cheng: Okay, so 8 00:01:16.110 --> 00:01:32.760 Jiaming Xu: In the second arrow. So you said that if you are just waiting to meet the CPU cycles gave us leave us with someone else that that the CPU give the give the time to process or the last birthday cake thrive in that process. 9 00:01:34.620 --> 00:01:35.790 William Cheng: Does the CPU to what 10 00:01:36.810 --> 00:01:43.200 Jiaming Xu: Gave the gift time given the execution time to thrive, or the process. 11 00:01:44.040 --> 00:01:53.370 William Cheng: Yeah, so, so that's what we're going to learn. So the in chapter five, how to implement a thread. Okay. So right now, thread is just sort of a sort of an abstraction. 12 00:01:54.090 --> 00:01:58.140 William Cheng: You know that that you know the CPU is the one that actually executing code. 13 00:01:58.890 --> 00:02:04.380 William Cheng: Because you know it's the hardware that's executing code. So exactly what is a threat. So, you know, we don't really know exactly what it is. 14 00:02:05.280 --> 00:02:07.950 William Cheng: So in chapter two, we're sort of going to talk about this abstraction. 15 00:02:08.400 --> 00:02:21.900 William Cheng: Okay, we're going to talk about how to create threat. There's a way throw away for each other. How do the threat, you know, make sure that they don't interfere with other threads or these kinds of stuff. But India is just an abstraction, because the CPU doesn't really know about threads. 16 00:02:23.640 --> 00:02:26.460 Jiaming Xu: So the CPU only know the process. 17 00:02:27.090 --> 00:02:29.760 William Cheng: The CPU doesn't know about process. Either the CPU doesn't know anything 18 00:02:31.740 --> 00:02:35.580 William Cheng: So, chapter five, chapter five, we're going to see exactly what what what 19 00:02:36.480 --> 00:02:38.880 William Cheng: Later on, with them implement all these abstraction. 20 00:02:39.900 --> 00:02:40.320 Jiaming Xu: Okay. 21 00:02:40.680 --> 00:02:46.680 William Cheng: So so so you can sort of think about, I guess in the lecture I briefly talk about the threat sort of threat control block. 22 00:02:47.070 --> 00:02:54.570 William Cheng: So I'm assuming you know where the thread is, you know, it's a data structure right exactly what it is. It's more than a data structure. So, 23 00:02:55.350 --> 00:03:07.380 William Cheng: It's kind of hard to explain exactly what it is. Until you know we get to chapter five. And also, you know, Colonel. The first Colonel Simon, you have to implement threads. So, at that time, you're going to get a better feel of exactly what a threat is 24 00:03:08.280 --> 00:03:08.670 Okay. 25 00:03:09.780 --> 00:03:20.970 William Cheng: So, so, so, so, so this class is kind of a very interesting sort of teach you about these abstraction and sort of how to implement it. You can see that the abstraction is completely different from the actual implementation. 26 00:03:21.930 --> 00:03:25.050 William Cheng: Guys idea was to learn something totally new that we never see before. 27 00:03:25.920 --> 00:03:27.120 Jiaming Xu: Okay, thank you. 28 00:03:27.870 --> 00:03:28.410 William Cheng: You're welcome. 29 00:03:30.480 --> 00:03:32.040 Hardik Mahipal Surana: Good morning, professor or no. 30 00:03:32.070 --> 00:03:32.490 Yeah. 31 00:03:36.090 --> 00:03:37.470 William Cheng: Sure, go ahead. Okay. 32 00:03:37.650 --> 00:03:47.190 Hardik Mahipal Surana: So I had some confusion with respect to the user address space. The Colonel outer space. So this is with respect to the files in Section 1.3 33 00:03:48.660 --> 00:03:48.960 William Cheng: So, 34 00:03:49.110 --> 00:03:55.680 Hardik Mahipal Surana: You mentioned that the kernel space is essentially shared amongst all the user processes. 35 00:03:56.100 --> 00:03:59.010 William Cheng: And yes, I think I have a slide on that. Right. Yeah. This is a slide. 36 00:04:01.470 --> 00:04:16.500 Hardik Mahipal Surana: Here and when we create a file descriptor. I'm a little confused as to where does the file descriptor live the poor process file descriptor table the system wide file descriptor table. So is it a part of the extended address space. Is it a part of the 37 00:04:17.220 --> 00:04:19.770 Hardik Mahipal Surana: Processes are just based on how, where does that 38 00:04:21.150 --> 00:04:31.050 William Cheng: Yeah, the extended address space just means that it's outside the address space. So it's kind of us, you know, sort of a silly term to say that, you know, anything that the operating system keep for you. 39 00:04:31.680 --> 00:04:37.800 William Cheng: They're considered part of the extended address space, right. So if you look at this picture right here right this picture. Let me, let me 40 00:04:38.100 --> 00:04:47.880 William Cheng: sort of draw this picture right on the left hand side is your user space program. Right. So when we think about a user space prologue, we think about the address space. Okay, so here's the address space of the user space program. 41 00:04:48.420 --> 00:04:55.860 William Cheng: So inside your address space you have code. You have you have variables right global variable local variable or these kind of variables. So they are part of your address space. 42 00:04:56.460 --> 00:05:08.340 William Cheng: Okay, so when you open a file, while all these things are done inside operating system kernel. Right, so, so, so what you should think about is that every user space program has a file descriptor table that the colonel maintain the for you. 43 00:05:09.120 --> 00:05:22.260 William Cheng: Okay, so in this case the file, file descriptor table, it just a bunch of pointer that point to fall objects and inside the file object, the opportunities that will help you by keeping track of some of the some of the state information about your program inside these all objects. 44 00:05:24.660 --> 00:05:30.150 Hardik Mahipal Surana: Process file descriptor table and the system fine table are both part of the extended data space. 45 00:05:31.290 --> 00:05:38.760 William Cheng: So to get he says either stress is just sort of a concept, anything that's outside of address space. We're going to say that it's in your extended address space. 46 00:05:39.480 --> 00:05:46.470 William Cheng: Okay, so that that information is scattered all over the place all over the colonel all over everywhere else. It's just, I mean that it's not in your address space. 47 00:05:47.700 --> 00:05:52.440 William Cheng: Okay, so any information. The Colonel maintain for you. We call it in the extended address space. 48 00:05:54.990 --> 00:06:02.100 William Cheng: I mean, can also go to the extreme. And I said a while, you know, let's say that you're running a program you're backing up data into the cloud. 49 00:06:02.550 --> 00:06:07.350 William Cheng: Is the cloud in your extended address space that maybe 50 00:06:08.310 --> 00:06:15.210 William Cheng: So, so, so, so again, these are abstract concept, right, we only use the term extended address way to say well if it's on your address space. 51 00:06:15.510 --> 00:06:24.420 William Cheng: And if you have a way to reach it, even though you have to go across the you know the universe, you have to go across the planet. It's in your extended I just wait as long as you have a way to reach it. 52 00:06:26.910 --> 00:06:37.500 Hardik Mahipal Surana: And so I think it's slide number 79. Maybe I'll start with respect to closing the standard output file descriptor and replacing that with 53 00:06:39.570 --> 00:06:40.260 Like offline. 54 00:06:41.700 --> 00:06:44.280 William Cheng: Okay, so it's using a different number. 55 00:06:46.620 --> 00:06:50.580 William Cheng: Okay, so unless you're three. So today, we're basically talking about lecture three 56 00:06:51.660 --> 00:06:53.220 William Cheng: So, so is the slide. 57 00:06:53.340 --> 00:06:54.000 Hardik Mahipal Surana: Yes, yes, yes. 58 00:06:55.590 --> 00:07:01.440 Hardik Mahipal Surana: So in this, what we see is we close the standard output file descriptor. In the first line. 59 00:07:01.770 --> 00:07:03.240 Hardik Mahipal Surana: Right, and we we set 60 00:07:03.300 --> 00:07:09.360 Hardik Mahipal Surana: The we point the file descriptor one to this particular file right 61 00:07:09.480 --> 00:07:24.690 Hardik Mahipal Surana: So yes, output. So my question is, once we are done with using this file for our output redirection, what would be the procedure for us to close this particular file and reset the file descriptor one to again point to standard output. 62 00:07:26.070 --> 00:07:35.130 William Cheng: So when you can do so you can do exactly what we see over here you can close file descriptor. Number one, so in this case file descriptor number one will no longer be associated with this file. 63 00:07:35.640 --> 00:07:45.390 William Cheng: Okay, and then you can call open on the you know the you can you can call open on the terminal device or the you know the whatever device it is 64 00:07:46.500 --> 00:07:52.350 William Cheng: Okay, we haven't really talked about how to do that yet. Right. But since on a UNIX system or Linux system. 65 00:07:52.920 --> 00:08:03.090 William Cheng: Everything that's out there. They're all represented by a file. So if you want to talk to the keyboard. You want to talk to the display. You have to open a file that represent the keyboard and it this way. 66 00:08:04.830 --> 00:08:08.880 Hardik Mahipal Surana: So, is that also something that is stored on disk like 67 00:08:09.810 --> 00:08:18.360 William Cheng: The file system hierarchy, right, every file represent something right, it could be a fallen to does it could be a device. It could be you know what will. Whatever it is. 68 00:08:19.410 --> 00:08:22.710 William Cheng: So if you want to have access to a device, you need to open a file. 69 00:08:24.960 --> 00:08:36.540 Hardik Mahipal Surana: And so you mentioned that the file descriptor table and everything will be a part of the extended address space and the parent and the child process will share the same address space. Correct. 70 00:08:37.830 --> 00:08:41.640 William Cheng: And so, so in this class. We're going to learn index. 71 00:08:41.640 --> 00:08:42.300 Hardik Mahipal Surana: Data spacing. 72 00:08:42.720 --> 00:08:48.840 William Cheng: Right, so, so, so, yeah. For sixth edition Unix a parent, the parent and the child process, they do not share the address space. 73 00:08:49.320 --> 00:08:59.010 William Cheng: And newer units allow you to share address space, but the the older UNIX and there's no sharing of the address space, do they share the extended address space part of it. 74 00:09:00.060 --> 00:09:08.280 William Cheng: Okay, so, so part of this class we're going to sort of see in sixth edition Unix which part of the extended address space a share. Which part of that extend the address space. They do not share 75 00:09:08.880 --> 00:09:13.920 William Cheng: Okay, so one thing that we see already over here, right, if you go to the, you know, this slide over here. 76 00:09:14.940 --> 00:09:22.290 William Cheng: Okay, it says the file descriptor table that's clearly in the extended address space. Okay, the file descriptor table over here. 77 00:09:22.800 --> 00:09:37.260 William Cheng: It's per process. Right. So every process has their own file descriptor table. So that's sort of tells you that they don't share the file descriptor table. Okay, but the file descriptor table can point to the same file object. So therefore, they can share the same file object. 78 00:09:38.460 --> 00:09:39.390 Hardik Mahipal Surana: Oh, okay. I got it. 79 00:09:39.450 --> 00:09:49.530 Hardik Mahipal Surana: So, so my question actually was that if the same file would to be opened using different modes. Let's say the parent opens it and read only mode and the child opens the same file in right mode. 80 00:09:49.830 --> 00:09:58.860 Hardik Mahipal Surana: So based on what you said. Now, I think we will have two different file descriptors in the process by descriptor table, but they would point to the same file object in the system. 81 00:10:00.630 --> 00:10:07.980 William Cheng: Yes. Yeah, so, so, so, so if they pointed the same file object in the system fallout table, then there's only one access mode. 82 00:10:08.490 --> 00:10:18.000 William Cheng: Right, so therefore you cannot say that, oh, the parent wants to have read only access in the child. Want to have relax as well. I indicated doesn't work right okay this picture sort of show you that it will not work. 83 00:10:18.540 --> 00:10:24.360 Hardik Mahipal Surana: Okay, so technically it's not possible for the same file to have different modes in the in the parent and the child. 84 00:10:24.390 --> 00:10:33.690 William Cheng: Depends on the operating system. So our classes, mainly talk about sixth edition operating a sixth edition Unix. So in sixth edition Unix. Yeah, this is the way was 85 00:10:34.710 --> 00:10:37.950 William Cheng: Okay right but but but but but if you think about sort of the in the 86 00:10:38.460 --> 00:10:49.320 William Cheng: In the real case right if I have a pen and tell process. One of them has only read access to a file, the other has the idea, otherwise somehow has rewrite access to the file, it seems to be a little bit incompatible right 87 00:10:50.850 --> 00:10:58.800 William Cheng: Okay, so the question is that when you were when you were, you know, implementing or designing the cynicism law, you need to make a decision to say whether whether this is allowed or not. 88 00:10:59.040 --> 00:11:03.780 William Cheng: If it's allowed you need to sort of make sense out of it. If it cannot do that. Maybe it's best that you don't allow it. 89 00:11:05.370 --> 00:11:16.170 William Cheng: Ok, ok. So, again, that that's a more advanced operating system topic. So we're not going to talk about that in this class. So in this class. We're going to sort of just show you how things work. And then how they actually they will be able to share the same 90 00:11:16.560 --> 00:11:22.230 William Cheng: The same same follow jack. Okay, we're not going to allow you to open. You know, this file object in a different mode. 91 00:11:23.310 --> 00:11:24.270 William Cheng: Okay, so 92 00:11:24.300 --> 00:11:43.110 Hardik Mahipal Surana: This. So, the same question, if I were to ask with respect to multiple threads in the same process. So if the same file were to be opened in indict mode lets say by different threats, how the representation be in the in the file descriptor table because that 93 00:11:43.260 --> 00:11:50.430 William Cheng: So, so in this case you can see this this picture over here. Here is the address space. And again, we use the address space to represent a process. 94 00:11:50.670 --> 00:11:58.770 William Cheng: So in this process. If we have multiple threads. I mean the way I'm going to joy is I'm going to have multiple threads running this process guys are here three threads on on this process. 95 00:11:59.160 --> 00:12:14.130 William Cheng: Okay, there's still only one file descriptor table the file descriptor table every pointer over here only point one file object. Okay. So, therefore, all the threats inside your process. You know, there's no way for you to have a file that opening different modes. 96 00:12:15.900 --> 00:12:16.080 William Cheng: Know, 97 00:12:16.500 --> 00:12:25.770 Hardik Mahipal Surana: If they were to be opening the same mode. Let's have you open all three threads in read only mode. But we're actually reading different positions in the same file. 98 00:12:26.370 --> 00:12:39.480 William Cheng: Right, so they will be dangerous. So, so again the operating system doesn't prevent you from doing something bad. Okay, so if you want to do things that doesn't make sense. You can go ahead and do it. Well, you're going to end up with. Are you going to end up with unpredictable result. 99 00:12:40.290 --> 00:12:52.260 William Cheng: Okay, so, so when you write your program, you need to determine, do I want unpredictable results I want predictable result if you want predictable result, you need to learn how to write your program properly. So this way you will always get predictable results. 100 00:12:53.520 --> 00:13:02.640 William Cheng: Okay. Okay, so, so if you have three threads. You want to simultaneously refund the same file at different places. How's that gonna work. Well, you know, it's gonna be unpredictable. 101 00:13:03.540 --> 00:13:12.420 William Cheng: Okay. Okay, so therefore it's better, you don't write your code that way. But are you allowed to write your code that way. Yeah, you're allowed to write your code that way, but don't expect to have the correct behavior. 102 00:13:13.680 --> 00:13:22.890 William Cheng: Okay. Okay, so, so it is possible for when you try to read the file from one place, as it turns out, you can end up reading the file from a different place. Okay, so then you shouldn't be surprised. 103 00:13:24.510 --> 00:13:34.770 Hardik Mahipal Surana: And at any point in time when once we spawn multiple threads. Do we know at any point in time, which is currently the active one and which are the passive ones. 104 00:13:35.190 --> 00:13:40.860 William Cheng: Well, I mean, you don't know right because if. What if you have multiple CPU, you can run all these things in parallel. I so 105 00:13:41.700 --> 00:13:44.820 Hardik Mahipal Surana: Yes, I wish to ask with respect to one CPU. 106 00:13:46.140 --> 00:13:53.610 William Cheng: In what was so, so again, your code needs to work when there's multiple CPU or one CPU. You wouldn't write a program to say if there's only one CPU. I want to do this. 107 00:13:54.240 --> 00:14:03.090 William Cheng: Okay, so, so, so, so, for example, right, if you're running your application program over here. You want to try to find out how many CPUs are there, is there a way to find out how many CPUs are there. 108 00:14:04.440 --> 00:14:15.330 William Cheng: And the application program, maybe doesn't have a way right you know because you know the operational model provide the abstraction to stay that way it doesn't really matter how many PCB. You have your program will always run in a predictable fashion. 109 00:14:16.320 --> 00:14:19.920 William Cheng: Okay, so maybe the opposite wouldn't want you to know how many, how many CPUs are there. 110 00:14:22.230 --> 00:14:27.750 William Cheng: So yeah, maybe there are some operating system that will give you that information. Some operating system, who just will not give you that information. 111 00:14:31.800 --> 00:14:39.870 William Cheng: Alright, so, so, so in chapter two. So chapter. So you keep asking question about multi threading right Chapter two is multi threading. We're going to give you a multi threading model. 112 00:14:40.350 --> 00:14:55.260 William Cheng: Okay, so these are the API that you use to manipulate threads and stuff like that. You can see that there's none of those you know function will tell you how many CPUs there. Okay, okay, a lot of information are hidden away from you intentionally so that you will write your code correctly. 113 00:14:57.600 --> 00:14:57.870 William Cheng: All right. 114 00:14:58.590 --> 00:15:11.790 William Cheng: Thank you. So it's a little so I know this is this is a little bit unsatisfying. But you know what we're going to try to do so to sort of teach you one way to write the program correctly so that it will always have predictable behavior. Okay. 115 00:15:12.000 --> 00:15:18.600 Hardik Mahipal Surana: So basically, we need to have a deeper understanding of the kernel that we are technically using as the application programmers. 116 00:15:18.960 --> 00:15:19.350 William Cheng: A 117 00:15:19.470 --> 00:15:21.090 Hardik Mahipal Surana: well designed would actually 118 00:15:21.270 --> 00:15:32.370 Hardik Mahipal Surana: Be no no no no not. No, not really. Okay, so, so we're going to teach you an application program model. So I think towards the end of this class against you know the next step, the threads over here. 119 00:15:34.590 --> 00:15:37.500 William Cheng: Let me go there quickly, whereas it 120 00:15:40.590 --> 00:15:46.980 William Cheng: OK, we are talking about the positive stress standard. Okay, so that's a model of threat how the second 121 00:15:47.520 --> 00:15:55.770 William Cheng: Haha, two thirds are allowed to interact interact with each other. So this will be the, you know, sort of the model, though, that we talked about. And the reason is that positive 122 00:15:56.160 --> 00:16:09.810 William Cheng: Model is very, very popular pretty much any kind of system that you run into. They all support politics threads. Okay, so, so therefore, in our class we're going to learn about politics because, why did you learn about politics thread you can implement multi threading any operating system. 123 00:16:11.130 --> 00:16:25.200 William Cheng: Ok ok so this dress or, you know, some positive stress or tells you you know how the sort of a few limited way that these are allowed to interact and then we need to sort of learn how to use this particular model to implement anything we want. 124 00:16:29.040 --> 00:16:29.430 William Cheng: Okay. 125 00:16:33.120 --> 00:16:37.470 Jiaming Xu: Hi Professor who do go back to the latter side initial 126 00:16:37.710 --> 00:16:42.060 William Cheng: Maybe the number is 5454 127 00:16:42.090 --> 00:16:42.870 Okay, yeah. 128 00:16:45.660 --> 00:17:03.270 Jiaming Xu: Yeah, so suppose there's a case that there are two process which are point to the same file point to that, maybe, maybe the same file object, but they are different. But the cursor different and I mean the to process really the different location from one file. 129 00:17:04.500 --> 00:17:04.950 William Cheng: Yes. 130 00:17:05.640 --> 00:17:08.250 Jiaming Xu: So where should where should 131 00:17:10.260 --> 00:17:14.190 Jiaming Xu: The girl shows in the in the fifth and final table. 132 00:17:14.520 --> 00:17:21.270 William Cheng: Right. So the example that I gave, is that, you know, these two processes are sharing the same file. They are usually the parent and the child process right 133 00:17:21.420 --> 00:17:28.110 William Cheng: So when you create a child Ross as you get a copy of the address space, you're going to get your own file descriptor table and now you end up sharing the same file. 134 00:17:28.980 --> 00:17:34.050 William Cheng: Okay. So in this case, these are, these are the parent and the child dependent child, we saw that before you sort of 135 00:17:34.830 --> 00:17:38.250 William Cheng: You know that the way that you create them, you call forth right and now they 136 00:17:38.820 --> 00:17:48.240 William Cheng: You know, the, the, the, the child processes will share the same address space. So the program was written for both the child the parent, the parent process and the child process. 137 00:17:48.660 --> 00:17:58.230 William Cheng: Okay, so you know where you can sort of think about is that the same program, write the code for the parent and radical for the for the child. And if you have a bug in your code law that thing's not going to work correctly. 138 00:17:58.830 --> 00:18:06.630 William Cheng: Okay, so what you're talking about over here is that the parent process over here was set the cursor position to one place and the child process will serve the cursor proceeded to somewhere else. 139 00:18:06.840 --> 00:18:13.230 William Cheng: And now you try to share the same file, while in that case, you're going to end up with I'm predictable result. Okay, so don't write your code that way. 140 00:18:13.770 --> 00:18:22.050 William Cheng: If you want to write your code. If you want to write it. If you want to write your code so that the parent and the child can share a file. You have to do it very, very carefully. 141 00:18:23.070 --> 00:18:23.970 Jiaming Xu: Okay, but 142 00:18:24.120 --> 00:18:24.510 William Cheng: It doesn't 143 00:18:25.680 --> 00:18:26.370 William Cheng: Do that yet. 144 00:18:27.030 --> 00:18:34.650 William Cheng: So later on you know in the in the semester. We're going to sort of present to you one way how the parent and the child can use the file system to communicate with each other. 145 00:18:35.700 --> 00:18:36.090 Jiaming Xu: Okay. 146 00:18:36.600 --> 00:18:37.170 William Cheng: Okay, so 147 00:18:37.620 --> 00:18:38.070 William Cheng: Much later, 148 00:18:38.730 --> 00:18:55.500 Jiaming Xu: So could you give me an example that they are to process point to the same file. So as you said before the reference count should be too if they are two out if they are 2% point one file. So the reference can't come to be to 149 00:18:57.600 --> 00:19:02.340 Jiaming Xu: The file location is the same, or can be different so 150 00:19:02.430 --> 00:19:08.370 William Cheng: In this case, yeah, if they're using the same file object, then they share the same file location if they share the same cursor position. 151 00:19:09.210 --> 00:19:09.600 Jiaming Xu: Okay. 152 00:19:10.290 --> 00:19:13.680 William Cheng: Okay, so, so it's kind of, it's very difficult to make them synchronized. 153 00:19:15.600 --> 00:19:15.930 Jiaming Xu: Okay. 154 00:19:16.200 --> 00:19:18.990 William Cheng: Okay, so you got to be very, very careful what you're sharing about 155 00:19:19.860 --> 00:19:21.840 Jiaming Xu: Okay, thank you. Okay. 156 00:19:21.900 --> 00:19:22.080 Yeah. 157 00:19:25.350 --> 00:19:34.830 William Cheng: So again, the sort of the opportunities and sort of give you all these tools, you know, these tools are pretty powerful, but you got to be very, very careful with them. Otherwise, otherwise you know you guys will will give you the wrong results. 158 00:19:44.880 --> 00:19:46.050 William Cheng: Any other questions. 159 00:19:49.140 --> 00:19:52.080 Lalit Gupta: Hi, I have a question. In this slide, only okay 160 00:19:53.340 --> 00:20:11.100 Lalit Gupta: So suppose I have two programs and I want to read a file, the same that people don't want to read the same file and suppose the one program read up to a certain point in the file will affect in program will start from that point, or will start from the beginning. 161 00:20:11.670 --> 00:20:13.800 William Cheng: Yeah, so let me 162 00:20:15.780 --> 00:20:24.720 William Cheng: Let me do this a little bit. Okay. So when you say that they share the same file, right, so remember there are two things. One is one is that this thing, this thing what he wrote over here is a file object. 163 00:20:25.650 --> 00:20:31.530 William Cheng: Okay, so we can have two programs share the same file object when they share the same project typically their parent and a child process. 164 00:20:31.980 --> 00:20:41.730 William Cheng: Okay. And remember the last one over here is I know point or the I know point to point to a file. So when you say that to process each share a file. Maybe they are sharing something that they point to 165 00:20:42.450 --> 00:20:47.580 William Cheng: Okay, so this case they're completely different right one is ensuring the file object. The other one is shared the actual file. 166 00:20:47.910 --> 00:20:54.690 William Cheng: Okay, so if you if they're sharing the actual file, but they are not sharing the file object. So one of them will have, you know, one file optic over here. 167 00:20:54.900 --> 00:20:59.550 William Cheng: The other processes will using this particular file object. Well, in that case, they can be working at different places. 168 00:21:00.060 --> 00:21:10.680 William Cheng: That they can work be working at different places have the same file. Okay. But if they share the same file object one. In that case, there's only one cursor position. Right. So in that case, you know that. Then again, there's going to be more conflict. 169 00:21:12.180 --> 00:21:13.950 William Cheng: Okay, thank you. 170 00:21:14.460 --> 00:21:23.640 William Cheng: Okay, so, so yeah, so it is a little weird, right. So remember I know representative file. So it is possible. After multiple levels of indirection. They might Indian Point of the same thing. 171 00:21:24.000 --> 00:21:31.770 William Cheng: Okay. So, for example, like your computer screen, right, your computer screen is, you know, I guess. By default file descriptor one connect to the 172 00:21:33.600 --> 00:21:39.450 William Cheng: Connected display it is possible you have multiple programs, trying to write to the display at exactly the same time, right. 173 00:21:39.990 --> 00:21:50.160 William Cheng: Okay, so, because as you see that we can run multiple program in the background parallel and we're gonna try to print that exactly the same time while in that case. Yeah, the character will show up on the screen and a really random fashion. 174 00:21:50.910 --> 00:21:55.110 William Cheng: Okay, so that's why sharing look that's why sharing will look like. Okay, things will have random 175 00:21:57.900 --> 00:21:58.470 Business 176 00:21:59.640 --> 00:21:59.940 William Cheng: Okay. 177 00:22:02.610 --> 00:22:08.520 Lalit Gupta: Also, I have one more question regarding the process control block that you talked about in one of the slide. 178 00:22:08.880 --> 00:22:21.210 Lalit Gupta: Okay. Does, does the process go to India called pass control structure does the parent have the knowledge about the child, which are alive, or does it only know about their child. 179 00:22:23.220 --> 00:22:30.990 William Cheng: Yeah, so, so, you know, so you know for for process inside the Colonel. The Colonel needs to know everything. 180 00:22:31.860 --> 00:22:41.430 William Cheng: Okay, so you got to make sure that when you are trying to design a colonel. The Colonel would know that for this particular process, we shall processes are live. Which child processes are dead. 181 00:22:44.460 --> 00:22:45.840 Lalit Gupta: In digital structure, we can 182 00:22:46.410 --> 00:22:55.830 William Cheng: We can, but this data structure is incomplete, right, because what happened. Tell you what the rest of the data structure is right. So maybe then the rest of the data structure. There's another list for all the child processes that are running 183 00:22:57.660 --> 00:23:06.120 William Cheng: Okay, so it is possible. That's how we keep track of where but maybe they use a different kind of way to it. Maybe they used to treat data structure and what we don't know. Right. Because a lot of stuff is not being drawn here. 184 00:23:09.420 --> 00:23:09.660 William Cheng: Okay. 185 00:23:19.500 --> 00:23:20.550 William Cheng: Any other questions. 186 00:23:23.160 --> 00:23:24.450 Wookyum Kim: Oh, I have a question. 187 00:23:25.110 --> 00:23:25.410 Sure. 188 00:23:26.730 --> 00:23:27.600 Wookyum Kim: In the slight 189 00:23:27.720 --> 00:23:29.700 William Cheng: At 50 190 00:23:30.000 --> 00:23:32.430 William Cheng: Yeah okay let me go there. 191 00:23:44.370 --> 00:23:49.350 Wookyum Kim: I don't think this one's. Um, it's, I mean it. It was about 192 00:23:50.670 --> 00:23:54.960 Wookyum Kim: The explanation about the parent and child. 193 00:23:56.220 --> 00:23:57.000 Wookyum Kim: Processor. 194 00:23:57.450 --> 00:23:58.320 Wookyum Kim: I mean persist. 195 00:23:58.950 --> 00:24:02.370 William Cheng: Okay, so that's why we were before. At the beginning, over here. 196 00:24:03.810 --> 00:24:04.230 William Cheng: This one. 197 00:24:09.480 --> 00:24:13.920 Wookyum Kim: Is it is it also with the codes of the 198 00:24:15.300 --> 00:24:17.580 Wookyum Kim: Yeah, just want this one. Yeah, before 199 00:24:17.700 --> 00:24:18.810 William Cheng: Before this, okay. 200 00:24:18.870 --> 00:24:19.200 William Cheng: This one. 201 00:24:19.890 --> 00:24:20.490 Yeah. 202 00:24:22.290 --> 00:24:22.560 William Cheng: Okay. 203 00:24:23.280 --> 00:24:33.660 Wookyum Kim: So during the explanations about the dress code. Um, so after I mean for that in the second line. Oh. 204 00:24:35.190 --> 00:24:37.500 Wookyum Kim: Oh purposes. You said 205 00:24:38.700 --> 00:24:43.500 Wookyum Kim: I'm parent and child is sleep and they're the pork. 206 00:24:43.890 --> 00:24:46.050 William Cheng: Right, so let me go to 207 00:24:49.470 --> 00:24:50.640 William Cheng: Even like things like this. Right. 208 00:24:51.060 --> 00:24:51.270 Wookyum Kim: Yeah. 209 00:24:51.300 --> 00:24:56.340 William Cheng: Okay, so yeah, so you call for he going into the kernel and we create a child processes said, Oh, yeah. 210 00:24:56.760 --> 00:25:08.910 Wookyum Kim: Yeah. And because I think there is no I mean it's before. Wait, so wait functions then. But why these sleep. I mean after the fork. 211 00:25:09.630 --> 00:25:11.070 Wookyum Kim: I mean, the parent is 212 00:25:12.210 --> 00:25:17.790 William Cheng: Well, so this is in the middle of the fork. Right. So, so what we call fork. It's a system called so you go inside the kernel. 213 00:25:18.000 --> 00:25:29.310 William Cheng: And these are the Colonel, we're going to create a child process we're going to, you know, create this the process control block for the child. We're going to set up all these data structure. And now we're going to return to both parent and the child simultaneously, we have multiple CPUs. 214 00:25:29.760 --> 00:25:34.050 William Cheng: Yeah, right. So, so we haven't gotten here yet. Right. So right now, we're still in the middle of the fork. 215 00:25:34.320 --> 00:25:39.060 William Cheng: So the next thing that we do over here is that we're going to return to the parent and we're going to return to the child. 216 00:25:40.290 --> 00:25:41.580 Wookyum Kim: Okay, so 217 00:25:41.610 --> 00:25:46.620 William Cheng: As soon as we do that the child will start executing code over here and apparel store excellent call right here and what 218 00:25:46.860 --> 00:25:56.130 Wookyum Kim: I mean, drink in the lecture videos, you said that. I mean, before exit exit l the parent is sleeping right 219 00:25:57.030 --> 00:26:08.790 William Cheng: Yeah so. So on this slide right the Paris star running already. Right. But, you know, in the meantime, they also return to the chair right so again within this picture sort of try to capture all different kinds of situation depend on how many CPUs, you have 220 00:26:09.060 --> 00:26:13.590 William Cheng: depends on who's going to run first who's going to run. Second, so it's kind of complicated, right. So, so 221 00:26:14.160 --> 00:26:18.840 William Cheng: So, so, yeah. So what happened is that is that we end up. I'm on the legislature, I can only follow one thread. 222 00:26:19.380 --> 00:26:27.960 William Cheng: Okay, so therefore, in this case, we're gonna we're going to execute the child first. OK, so the parent has returned already. It hasn't got here yet. He hasn't got to the way system call yet. 223 00:26:28.500 --> 00:26:36.630 William Cheng: But the child is will the slides are. We are going to start following the child. Okay, so the child over here will go to execute exact out 224 00:26:37.530 --> 00:26:50.910 Wookyum Kim: I mean, I mean, I mean, before the parent is return. I mean, parents, I mean the parent is PhD. I mean, yeah, parent is returned from the operating systems. It is slipped in the corner right 225 00:26:51.750 --> 00:26:58.680 William Cheng: No, no, no. So this example right over here, look at this picture over here, this arrow means that it has returned from the colonel already 226 00:26:59.370 --> 00:27:00.720 Wookyum Kim: I mean, before return 227 00:27:01.590 --> 00:27:04.230 William Cheng: Before it return. So do what's right here. Right. 228 00:27:04.290 --> 00:27:05.070 Wookyum Kim: Yeah yeah yeah yeah 229 00:27:05.100 --> 00:27:05.370 Yeah. 230 00:27:06.840 --> 00:27:08.130 William Cheng: Okay, well, what about this life. 231 00:27:08.730 --> 00:27:14.190 Wookyum Kim: Yeah. So after that. So the actor for peace. Cool, cool. I mean, yeah. 232 00:27:14.490 --> 00:27:16.380 William Cheng: The right now we're in the, in the middle of the quarter. 233 00:27:16.860 --> 00:27:28.020 William Cheng: We're in the middle of the fork system called right for a system called the system because we come into the Colonel. The Colonel is going to do a bunch of stuff preparing all these data structure and now it's ready to go back to the user space to run the parent and run the child. 234 00:27:28.440 --> 00:27:31.710 Wookyum Kim: Ah ok so that application is sleeping. 235 00:27:31.980 --> 00:27:35.400 Wookyum Kim: Right now, because I mean the threads running on the corner. 236 00:27:35.910 --> 00:27:41.970 William Cheng: Right, because then they make a system cause right so the so the user space program, they're sleeping and now we're doing all the stuff inside the cardinal 237 00:27:42.390 --> 00:27:43.980 Wookyum Kim: Know, okay, okay, okay. Thank you. 238 00:27:44.280 --> 00:27:44.550 Okay. 239 00:27:55.980 --> 00:27:58.350 William Cheng: Anyone else has a question. I'll 240 00:27:58.380 --> 00:28:01.710 Wookyum Kim: Purposely. Actually, I have one more question about the work 241 00:28:02.400 --> 00:28:07.860 Wookyum Kim: Can I yeah I'm so it's about that the 242 00:28:08.880 --> 00:28:18.930 Wookyum Kim: The conditions for that each line. So the home. So it should be smaller than 1024 characters. Right. 243 00:28:22.080 --> 00:28:23.520 William Cheng: So, 244 00:28:26.280 --> 00:28:33.960 William Cheng: Yes, over here, the lines. The if the line is longer than 1024 characters, including the backslash. And at the end, the line that's considered there. Yeah. 245 00:28:35.040 --> 00:28:36.000 Wookyum Kim: I'm 246 00:28:37.440 --> 00:28:38.190 Wookyum Kim: I'm 247 00:28:38.760 --> 00:28:54.390 Wookyum Kim: Okay, so and so I look up the discussions lecture slides. I mean, the tentative ones, and there is a quote that both the buffer and the buffer size is 1026 248 00:28:54.840 --> 00:29:05.220 Wookyum Kim: Right. Why is it 1026 because, I mean, including the new character than it should be 1025, I guess. 249 00:29:05.520 --> 00:29:06.270 William Cheng: Right, yeah. 250 00:29:06.630 --> 00:29:07.020 Wookyum Kim: Yeah. 251 00:29:07.350 --> 00:29:10.980 William Cheng: So you can use anything you why these 2000 20,000 50,000 252 00:29:11.400 --> 00:29:12.030 William Cheng: It doesn't matter. 253 00:29:12.840 --> 00:29:14.400 Wookyum Kim: OK. OK, I see. 254 00:29:14.580 --> 00:29:24.240 William Cheng: Rather, the idea here is that if he is a large enough buffer, then as soon as you return a lot. You can see could figure out how long the line is if the line is bigger than 1024 you print it around messaging across your program. 255 00:29:24.720 --> 00:29:28.800 William Cheng: Okay, alright. So, so make your life a little easier by using a larger buffer. 256 00:29:29.910 --> 00:29:34.620 William Cheng: You don't have to be just right. Right. So he saw somebody will try to get it just right and then miss a character. 257 00:29:34.860 --> 00:29:37.680 William Cheng: So in the end, the program doesn't run correctly. Right. So, just use it larger buffer. 258 00:29:38.160 --> 00:29:53.970 Wookyum Kim: Okay, and then then I mean for that. I mean, implementing the court. I mean codes in years, then, should I like I mean to check this adder, then, should I like if there is a little characters in that our buffers in that way. 259 00:29:54.540 --> 00:30:01.920 William Cheng: Oh no, you know, the, it depends on which function you use if you use F get f guess guarantee to put a no character at the end. 260 00:30:02.970 --> 00:30:03.990 Wookyum Kim: Okay, then what if 261 00:30:04.110 --> 00:30:10.140 Wookyum Kim: I mean, what happens is that the line is more than the longer than the buffer. 262 00:30:11.100 --> 00:30:18.930 William Cheng: Right. So what you would do. So you're gonna you're gonna end up with the line right where the last character is backslash zero, but the character right before that is not a backslash em. 263 00:30:23.100 --> 00:30:31.230 William Cheng: Okay, so if you have a line that's shorter than the buffer right when it gets returned the last character before the beta zero has to be a backslash yeah 264 00:30:32.340 --> 00:30:32.550 William Cheng: Okay. 265 00:30:32.610 --> 00:30:37.890 Wookyum Kim: What what happens. I mean, if that offers is shorter than that the line. 266 00:30:38.970 --> 00:30:39.420 Wookyum Kim: I mean, 267 00:30:39.600 --> 00:30:43.800 William Cheng: Yeah, if the buffer is shorter than the line, right, so what's going to happen is that it's gonna 268 00:30:44.760 --> 00:30:47.880 William Cheng: You know is that are returned to live without the backslash and 269 00:30:49.110 --> 00:30:50.040 Wookyum Kim: Then 270 00:30:50.220 --> 00:30:52.050 William Cheng: Then it's really not a line right it's a partial line. 271 00:30:53.250 --> 00:30:53.610 William Cheng: Yeah. 272 00:30:53.640 --> 00:30:56.610 Wookyum Kim: Then, but is there a state or new character in there. 273 00:30:56.640 --> 00:30:59.850 William Cheng: I mean, yeah, yeah, yeah. F gets guaranteed to put a note character. 274 00:31:02.310 --> 00:31:11.820 William Cheng: So, so when you make this function called you got to know exactly what the function call is promising you right so he promised you that will put a backslash zero at the end. So therefore you should you should trust it. 275 00:31:12.930 --> 00:31:15.090 Wookyum Kim: Okay, okay. Yeah. Thank you. Okay. 276 00:31:23.820 --> 00:31:27.270 William Cheng: Any other question about lecture or warm up one 277 00:31:40.350 --> 00:31:41.340 William Cheng: No, no more question. 278 00:31:47.790 --> 00:31:49.350 William Cheng: Okay, there's no more questions. 279 00:31:50.370 --> 00:31:52.230 William Cheng: I'm, I'm going to end the lecture. Now, 280 00:31:54.840 --> 00:31:55.860 William Cheng: Okay, last call. 281 00:32:00.480 --> 00:32:05.940 William Cheng: Alrighty, so I will see you you know tomorrow discussion section. Okay. All right. Bye. 282 00:32:06.360 --> 00:32:07.590 Wookyum Kim: Bye bye.