[00:00:02] Start the recording. Okay, cool, guys. So let us get started. We have 200 participants joined. Ready? So it's time for us to... So many of us are given marks out of 10 and some got full 10, maybe due to the digital layer MCQ in assignment one. Okay? See, I just [00:01:27] Rakesh's audio is coming. [00:01:29] Is this network glitch? [00:01:35] No, I'm just checking it. [00:01:41] No issues. [00:01:43] I'll get it corrected. [00:01:45] You don't have to worry. [00:01:46] It's not final late, right? [00:01:48] So video also on. [00:01:59] See, I don't have to ask this question again and again. [00:02:04] As far as syllabus is concerned, [00:02:06] you should consider that whatever we have covered [00:02:10] in the previous [00:02:11] week end [00:02:14] that would be included [00:02:16] ok cool [00:02:20] quiz format will be the same [00:02:22] multiple choice [00:02:23] you don't have to [00:02:26] it would be very similar [00:02:27] now I have not shared the screen yet [00:02:30] I will be [00:02:31] no not much of a difference [00:02:36] I want to [00:02:38] they have the quiz format [00:02:40] that is all I can [00:02:42] understand [00:02:43] so other than that there is no difference okay cool let us get back to our session [00:02:50] so it's some time that we have waited for good to go yeah that's right [00:03:01] this will be protected proctored no no no i don't think so i don't think except for the [00:03:09] semester exam and end semester exam i don't think others are proctored okay cool so [00:03:19] is there any advantage if it is not proctored [00:03:22] not sure [00:03:23] how is it so [00:03:25] ok cool let's get [00:03:29] started let me first [00:03:34] share my screen [00:03:35] ok can one of you confirm that [00:03:50] you are able to see my screen [00:03:51] currently you should be seeing [00:03:54] my [00:03:54] browser where I have connected [00:03:58] to this [00:03:58] ok cool [00:04:00] so I have shared my entire screen so that [00:04:04] you'll be able to see what I am moving in moving out that is objective so basically what we covered [00:04:11] in the last week is basically the process and the calls we understood theoretically what it is [00:04:20] but how can we understand that in a practical perspective by performing activities we are going [00:04:33] to exactly understand where to find them especially in the unix environment if you are [00:04:40] looking for windows environment then the alternate commands for the windows environment should get [00:04:47] you that information but our focus today is going to be in the unix environment in unix if you look [00:04:56] at it i have a vmware wherein i'm running a virtual machine which is running ubuntu operating system [00:05:06] so to this i have connected through putty so this is one terminal and also i have the second terminal [00:05:15] just in case if we want to basically absorb run in one terminal and absorb in the another terminal [00:05:27] so let me clear the screen and hopefully the font is visible and legible if not please let me know [00:05:36] i can increase the font so what are we going to do now we know that let me just open up a word [00:05:48] document let us start with the basic understanding a blank document so now here we know that [00:06:00] if we are running a program it is running in the user space so all the applications [00:06:11] run in the user space it could be a c program or it could be a python program it could be a [00:06:20] browser it could be a shell command or it could be any application that is developed [00:06:25] using any programming languages, whatever it is, any [00:06:30] applications, it is running in the user [00:06:34] space. Now when it is running in the user space [00:06:38] we understood that it is [00:06:42] going to call [00:06:43] the library functions [00:06:51] of the operating system. [00:06:53] because without that [00:06:56] it will not be able to [00:06:58] actually [00:07:00] connect with the operating [00:07:02] system. The one that [00:07:04] is going to establish [00:07:06] let me cut [00:07:08] this off. It's not working for me [00:07:11] so let me paste this. [00:07:13] I have a space here so now [00:07:14] I can go ahead and [00:07:16] enter it. [00:07:18] What's happening? [00:07:27] Cool. [00:07:28] so now I can extend this [00:07:31] so we can expect it to call [00:07:33] the library functions or the system [00:07:37] called interfaces so it is going [00:07:40] to call the library functions [00:07:42] and in turn this library function [00:07:46] is going to call [00:07:48] the kernel we understood [00:07:52] that kernel is the core of the [00:07:54] operating system now this [00:07:57] kernel in turn [00:07:59] is, will [00:08:01] be called by [00:08:03] the library function [00:08:05] and this kernel in [00:08:07] turn will have access [00:08:09] directly to the [00:08:11] resources. [00:08:14] What resources? [00:08:15] The hardware resources which [00:08:17] we are expecting [00:08:19] which we are expecting [00:08:23] to be utilized by our [00:08:25] applications. So those are [00:08:27] managed resources and these managed resources could be something like tpu ram or it could [00:08:37] be a storage or it could be even a network device or it could be any other device that [00:08:45] is attached to the system so basically managed resources are the resources that is going to [00:08:54] be available within the system where our application is running. [00:09:00] Now, a library function is an interface provided by the library. [00:09:05] It could be a C standard library, or it could be a Python library, something like PyTorch. [00:09:16] And here, when we say a system call, it is just a request to the kernel for a service. [00:09:24] so what is that service [00:09:27] for example [00:09:29] you wanted to print something on the screen [00:09:32] so now the screen [00:09:34] is a resource which is available as an [00:09:36] output device for yourself [00:09:37] and you wanted [00:09:40] to print something on the screen [00:09:42] so that the user gets the information [00:09:44] so [00:09:46] for example [00:09:48] if you are going to use [00:09:50] C then we will use a function [00:09:54] called [00:09:55] printf. Sorry, this is part of the library [00:09:58] function. I'm typing it in the wrong area. So when you're using the [00:10:02] printf, then the printf library function [00:10:06] that may buffer the output and eventually use [00:10:10] write. That write function [00:10:13] is going to actually display the outcome to the [00:10:19] monitor so that the user will be able [00:10:23] to see the output. [00:10:26] Will we be able to identify [00:10:28] this entire process in this [00:10:30] example? Yes. [00:10:33] There are commands [00:10:34] such as ps. [00:10:37] We saw this command [00:10:39] in the last case. [00:10:41] Or it could be [00:10:42] something [00:10:44] related to uname. [00:10:47] Or it could be [00:10:49] get [00:10:50] pid. All these [00:10:52] commands are actually going to give the information to us the commands that we are going to use in [00:11:01] the shell basically instead of we interacting with the kernel directly we are interacting with [00:11:09] the shell and the shell is going to interact with the kernel so that means we have another [00:11:16] component in between this this is our user space so here application is going to run in the user [00:11:24] space this is the user interface which one the shell when we are going to give this command it [00:11:32] is not going to contact the kernel directly what it will do is it is going to contact the shell and [00:11:39] in turn shell will connect to the kernel and kernel will give the information back to the shell and [00:11:46] and tell we'll write the output in our console. [00:11:52] So there are commands which we have seen. [00:11:58] For example, fork is what we have seen last week. [00:12:03] Execute, wait. [00:12:06] These three we have seen as an example, [00:12:08] and these are all familiar programming interfaces. [00:12:11] Basically, this will interact [00:12:13] with the underlying Linux kernel operations. [00:12:17] have different names it could be execute ve or it could be wait for wait will communicate with [00:12:27] wait for and wait for will communicate with the operating system so there could be an another [00:12:34] function that our function might be calling our function will become the parent and the function [00:12:42] that our function is calling [00:12:44] will become child. [00:12:47] In the example of wait [00:12:48] and wait for, [00:12:50] wait is what we have used in our [00:12:52] program. So that gets executed. [00:12:54] So a process is getting created [00:12:56] for wait function. [00:12:58] And in turn, in case if wait is [00:13:00] calling another function called [00:13:02] wait for, then wait for [00:13:04] also is a different process. [00:13:07] But there is [00:13:08] a connection between wait [00:13:10] and wait for. [00:13:12] Now, all these things, the entire flow, right from the application to library functions, to shell, to kernel and resources is what we are going to actually experience today. [00:13:27] Now, this is my user interface. [00:13:33] This is the shell which I was referring to. [00:13:36] So whatever command we are going to execute here [00:13:39] or whatever command we are going to issue here [00:13:41] will be interpreted by the shell [00:13:44] and executed by the kernel. [00:13:47] Okay, cool. [00:13:49] For example, [00:13:51] we know there is a cat command. [00:13:54] This cat command basically is concatenate, [00:13:58] which is expected to display the content of a file [00:14:03] if we are using a file. [00:14:06] For example, if I'm using a file which is OS release, [00:14:12] which is available in ETC directory, [00:14:15] this cat will actually display the content of the release. [00:14:21] This we are very much aware of. [00:14:23] Uber is even a little familiar with Unix. [00:14:27] They know that this is what we get for a cat command. [00:14:31] This cat command, what exactly is happening? [00:14:34] Now the cat is what we have issued and this cat is going to the shell and the shell is going to interpret what cat is expected and then convert that for the kernel to interpret. [00:14:55] it, and in turn, kernel will, because the file, etc.os-release, is stored in our storage [00:15:07] device, that is our hard disk, in this particular virtual machine. [00:15:12] So that means this file is to be opened, and then read the content of this file, put it [00:15:24] in the memory space. [00:15:25] So the first thing, kernel, what it will do is, it will churn out a process to open the file, etc. slash os-release. [00:15:39] Once this file is opened, this is going to be kept in the memory. [00:15:45] Kept in the memory. [00:15:47] Once it is available in the memory, it need not have to redirect to the stored hard disk. [00:15:57] Now from the memory, it will ask it to read. Read what? Read the content of the file. [00:16:04] So this is coming from the memory. [00:16:07] memory. And once it is read, [00:16:11] now the kernel, all this open [00:16:15] instruction, the read instruction, [00:16:19] now what it is supposed to do, it is [00:16:23] supposed to actually display the content of this file [00:16:27] on the screen. So that means it has to [00:16:31] do a write instruction, [00:16:36] Write to where? Write to the standard output. [00:16:42] What is the standard output? [00:16:44] It's nothing but our monitor. [00:16:47] Because we have not told where to write. [00:16:51] All I told is show me the content of this file. [00:16:55] Where? I have not mentioned. [00:16:57] So the default is standard output. [00:16:59] Standard output is nothing but the monitor. [00:17:02] So now this one command, [00:17:04] what we have issued, [00:17:05] This is what exactly has gone through behind the screen. [00:17:12] Now, let me come out of this. [00:17:18] Now, there is another command called uname-a. [00:17:23] So now this uname-a is actually going to give me the details of the system. [00:17:32] So where is it? [00:17:33] It is a Linux operating system. [00:17:35] it is the name of the system is [00:17:37] IIT Patna 2026 Atom [00:17:40] version it is running [00:17:42] is 7.0.0.0.34 [00:17:45] and [00:17:47] it is running Ubuntu [00:17:49] and when was it [00:17:51] it's running a GNU Linux [00:17:53] that means [00:17:54] open software [00:17:56] and [00:17:58] it is running in the [00:18:00] x86 architecture that means [00:18:03] the Intel [00:18:04] Basically, my laptop is having an Intel architecture. [00:18:08] In my laptop, I am running a virtual machine. [00:18:10] So it has installed the Intel architecture operating system in this virtual machine. [00:18:19] Okay, cool. [00:18:21] Now, I have, by default, language present in the Ubuntu operating system. [00:18:30] Nowadays, it installs by default. [00:18:31] so how will I know [00:18:34] whether it is there or not [00:18:35] gcc is the command [00:18:37] now if I give gcc [00:18:40] hyphen version [00:18:41] it tells me what is the version [00:18:44] it is available, in case if this [00:18:46] version, if this [00:18:47] software is not available then it will [00:18:50] not give the version number [00:18:51] so it's a copyright to free [00:18:54] software foundation [00:18:55] and there is no warranty [00:18:57] this is a free software but there is no [00:18:59] warranty. But we can use it [00:19:02] free of cost. We cannot distribute it. [00:19:06] Okay, cool. Now, [00:19:09] before even going ahead and understanding step by step [00:19:12] this entire process, I gave this as an example [00:19:16] to understand the process that's been [00:19:20] going behind the screen. [00:19:24] Now, before that, let us see if our [00:19:26] operating system is up to date. [00:19:29] So I'm just going to say APT. [00:19:33] Sorry, I'm going to use the Package Manager APT. [00:19:36] I'm going to ask update without any confirmation. [00:19:41] So now it is looking at all the packages that is available in Ubuntu operating system. [00:19:46] And it is comparing with its repository from where it has installed this operating system. [00:19:53] So there was one package that could have been updated. [00:19:56] but it still says that there are 38 packages that can be upgraded okay fair enough i don't [00:20:06] want to upgrade if i want to upgrade also i can do that but if you want to know which packages [00:20:11] so it says that run this command to see which are all packages can be upgraded so now you can see [00:20:20] there are so many open ssh also there is an upgrade that can be performed basically i'm [00:20:28] running 3.6 and i can get it upgraded to 3.7 of amd64 architecture python 3 also the net plan [00:20:39] of the python 3 is definitely having an upgrade available what i'm having is l1 to 5 it can be [00:20:49] upgraded to 1.2.1 [00:20:52] Ubuntu 5.1 [00:20:53] so this type of upgrades [00:20:56] in case if it is available [00:20:57] in the repository [00:20:58] this APT list [00:21:01] upgradable is going to help us to understand [00:21:03] am I going to [00:21:05] upgrade now so I'm not going to [00:21:07] upgrade now I don't know [00:21:08] sometimes it may take 5 minutes to upgrade [00:21:11] sometimes it can upgrade [00:21:13] it within 50 seconds [00:21:14] so I'm not going to [00:21:16] get into that but before that [00:21:18] I just wanted to see the tools that we are going to use today [00:21:24] is available in the server or not. [00:21:27] If it is available, then it won't install [00:21:31] because I'm going to give the command apt install. [00:21:36] And don't ask for my confirmation. [00:21:40] What we want, I want all the build essentials [00:21:44] because we are going to build packages. [00:21:47] to build essentials. [00:21:50] I'm going to use [00:21:51] a utility called [00:21:53] S-Trace. [00:21:55] And I just wanted to see like [00:21:57] if S-Trace is available in my [00:21:59] server. [00:22:01] And proc ps [00:22:03] and ps miscellaneous. [00:22:06] So [00:22:07] now [00:22:09] this provides [00:22:12] utility something. GCC anyhow [00:22:14] we have. GCC will [00:22:16] help us to compile our programs [00:22:18] because we are going to use a couple of C programs [00:22:21] in our demonstration today. [00:22:23] S-trace is basically to observe the system calls. [00:22:27] Once if you execute a program, [00:22:30] it will definitely log [00:22:32] and we can trace it using the S-trace utility. [00:22:37] And ps on top basically for processes we will be using. [00:22:42] And there is another command called ps3 [00:22:45] which is going to display [00:22:47] the process relationships. [00:22:50] Okay, which process [00:22:51] is the child process of [00:22:52] which parent [00:22:54] and is the parent [00:22:56] has waited until the child [00:22:59] is completed? [00:23:01] Did parent receive the output [00:23:03] from the child? [00:23:05] All those things we will be able to understand [00:23:07] if we can [00:23:09] understand the relationship between the [00:23:11] processes. So PS3 is [00:23:13] something that which is going to [00:23:16] it says [00:23:18] that all that you have [00:23:20] you don't have to install anything [00:23:21] you don't have to remove anything [00:23:23] and there are 38 packages that can be upgraded [00:23:26] which it is not upgrading [00:23:27] means our environment [00:23:29] is good enough [00:23:30] for our demonstration [00:23:32] okay cool [00:23:34] now let us do one thing [00:23:38] let us create a directory [00:23:39] so [00:23:41] where am i currently i am in root let me clear the screen i'm going to create a directory so that [00:23:50] we do not have to search for our scripts that we are going to use to so let me create it as process [00:24:00] call I have created [00:24:04] and I can change directory to [00:24:08] process call. So I am inside this new directory [00:24:12] which I have created. So we have two terminals. [00:24:16] This is our terminal where we are going to perform our operations [00:24:20] and I do have another terminal wherein in case if you want [00:24:25] to observe I will be displaying those [00:24:28] information in this small terminal we make it little [00:24:32] big in case it requires so let me go back to [00:24:36] my main terminal I'm back [00:24:40] here now we will [00:24:44] not treat a program's output as the [00:24:48] only evidence suppose you are writing a program [00:24:52] and that program is showing the output as expected [00:24:56] But our objective is not to understand the output from the program. [00:25:03] Our objective is basically to understand [00:25:06] how that program has communicated with shell, kernel, and hardware. [00:25:12] So we wanted to trace, so we will use S-trace utility [00:25:16] to examine what the program asks the kernel to do. [00:25:22] So if we can understand the relationship [00:25:24] between the application of the program, [00:25:26] with the kernel. [00:25:29] Then we will be able to understand [00:25:30] how the instructions are being processed. [00:25:36] Now, let me just give a command called echo. [00:25:44] Echo, we know that it is going to display whatever we type. [00:25:48] It will get displayed on the screen. [00:25:51] So for example, if I say echo my name, [00:25:55] it is going to display my name. [00:25:57] Similarly, if I say echo $$, [00:26:00] this $$ gives the process ID of the current shell itself. [00:26:06] As I said before, we are communicating with the shell. [00:26:10] If you want to know what is the process ID of the current shell [00:26:13] in which we are working, [00:26:15] this is the process ID of the shell. [00:26:18] So anything that is getting initiated in this shell [00:26:22] will also have the parent of parent as 2006 so sooner you have an another terminal so that [00:26:32] means each process will be different let us see yes so suppose you have a server and there are [00:26:42] like 20 people who have logged in remotely everyone is getting their own interface here i [00:26:49] have logged in using the same laptop, [00:26:52] so I have both the interfaces in my laptop. [00:26:54] Assume that I have logged in and all 200 of you [00:26:57] have logged in into the server. [00:26:59] Then obviously, the operating system has [00:27:02] provided tell for all 200 of us. [00:27:06] So every one of us is going to have a different process ID [00:27:11] for the environment in which we are working, the answer is yes. [00:27:17] now let me try the ps command the ps actually displays the process information [00:27:27] so now how many processes are actively running at this point of time [00:27:32] there are four processes that are running one is sudo second is su third is shell that is bash [00:27:41] And the fourth one is the PS. [00:27:44] So PS, Sundar, I understand that you have given the command right now. [00:27:49] So it has to be created a process. [00:27:53] And that process needs to have a process ID. [00:27:58] But where is this shell, su, sudo come from? [00:28:04] Suppose if I see who am I? [00:28:07] I am root. [00:28:09] How did I log in as root? [00:28:12] Did I log in directly? [00:28:14] to the root node actually i logged in as sundar into this server initially and now i exited [00:28:26] so currently i am sundar now i can give ps you can see only there are two the shell and ps [00:28:34] the sudo and su has disappeared why did they disappear because i exited from root [00:28:42] suppose if I want to log in as root again [00:28:45] I will give as sudo su hyphen [00:28:49] the moment I give this [00:28:51] it is asking for me to authenticate [00:28:54] so that I can become a super user [00:28:56] that is administrator [00:28:56] I am giving my password [00:28:59] now I have become root [00:29:01] so now if I give the ps [00:29:04] you can see this sudo [00:29:09] there is a process [00:29:10] this super user [00:29:12] is also a process [00:29:14] apart from that this shell [00:29:17] this shell's [00:29:19] process ID is [00:29:21] 2930 [00:29:22] but when we gave [00:29:24] PS here we also got a shell [00:29:27] with a process ID [00:29:28] 1968 [00:29:29] so will it change Sundar [00:29:33] actually it will not [00:29:35] change once you have logged in [00:29:37] till you log out [00:29:38] but [00:29:41] Earlier, if you look at it, I was already in the root. [00:29:45] So the shell's process ID is 2006. [00:29:50] Now it has become 200930. [00:29:54] So when I logged out, when I exited as a super user, [00:29:59] so this shell process has been terminated. [00:30:01] So the process ID is released. [00:30:05] Now when I become sudo, the root, [00:30:08] there is a need [00:30:11] for the shell [00:30:12] for the root [00:30:14] so it is now [00:30:17] running that process [00:30:18] so a new process ID [00:30:21] got assigned to the bash [00:30:22] that's why the process ID [00:30:24] between this bash [00:30:26] and this bash [00:30:27] bash is nothing but a born again [00:30:30] shell [00:30:30] it's one of the shells that is available [00:30:32] in the Linux operating system [00:30:36] especially Ubuntu [00:30:37] now [00:30:38] we also gave a name [00:30:41] we also gave a command [00:30:43] unim-a [00:30:45] and it was telling [00:30:47] exactly the environment [00:30:49] in which we are operating [00:30:50] so now the question comes [00:30:53] Sundar [00:30:53] is ps command [00:30:57] and unim-a [00:31:00] which you have used [00:31:01] just now and also [00:31:03] the echo command [00:31:04] which was displaying the process ID [00:31:07] for that particular [00:31:08] are all these system [00:31:13] calls [00:31:13] actually the answer is no [00:31:16] this ps [00:31:18] this echo and this uname [00:31:21] all these are not system [00:31:23] calls [00:31:23] then what are they Sundar [00:31:26] if these three are not [00:31:29] system calls I know I am working in Linux [00:31:31] operating system I am giving the [00:31:33] Linux operating system commands [00:31:35] on the interface and you say that it is not a system call it is not what it is is basically [00:31:47] application ubuntu has developed an application that is could be a shell script could be a program [00:31:57] using c or could be a library anything now these are all applications if you remember [00:32:05] we discussed initially [00:32:08] that [00:32:09] applications are running in the user [00:32:12] space. [00:32:14] If you say that [00:32:15] Echo is an application, [00:32:18] then is it running in the user space, [00:32:20] not in the kernel space? [00:32:22] No, it is running in the user space. [00:32:25] Echo will not [00:32:26] have access to the hardware. [00:32:29] It will make a system call to the [00:32:31] kernel [00:32:32] and kernel will understand that system call [00:32:36] and [00:32:37] provide the information back to the echo that is how it works now let us understand whether [00:32:46] the program let me create a program called identity dot c identity dot c okay that's right [00:32:58] now let me put that program people who are familiar with c will be able to understand [00:33:05] this program for the people who are not familiar with the c let me just give a quick explanation [00:33:13] of this program basically we need libraries of the programs so we are including the libraries [00:33:24] for example stdio is nothing but standard input output and dot h dot h is nothing but a header [00:33:31] file for a c programming language so since we are going to work with input and output [00:33:41] we need this header file to be added in our program this is a c program like that we have [00:33:48] other programs as well and then i'm writing a main function within the c program and i'm using [00:33:58] variables, I'm also defining [00:34:00] basically user name, [00:34:03] UTS name, and info. [00:34:05] Now I'm using [00:34:06] a [00:34:07] printf. Printf is a C [00:34:10] function. It's not [00:34:12] a cell function. It is a C function. [00:34:15] Now what I'm [00:34:16] trying to do is, using [00:34:18] this program, I'm trying [00:34:20] to print the [00:34:22] process ID [00:34:23] and [00:34:25] the U name of the system. [00:34:28] How will I get it? [00:34:30] Now I am calling the function getPID. [00:34:35] Whatever this getPID, that is going to give us the process ID. [00:34:42] And that will get assigned to this temporary variable. [00:34:48] And then this printoff is going to print both. [00:34:52] This is the standard structure. [00:34:56] And this is the variable that we are going to value that we are going to design. [00:35:02] sorry, receive using the getPID. [00:35:05] Similarly, we are going to get the uname. [00:35:10] Again, I'm using four print-off statements. [00:35:14] System, info.system, name. [00:35:17] Node, info.nodename. [00:35:20] Release, what is the version? [00:35:24] Info.release. [00:35:26] And mission, info.mission. [00:35:28] so basically i'm using a c function which is printf which is going to display this information [00:35:38] and it is going to get the value for this parameter by using info.system [00:35:46] where is this info.system comes from we have defined a structure info and it is going to get [00:35:54] that. There is the system name. [00:35:56] There is a node name. There is a release [00:35:58] of the operating system. [00:36:00] And there is the mission. [00:36:02] Okay, fair enough. And I am [00:36:04] finally returning 0. [00:36:06] So this is the structure of the [00:36:08] C program. Let me save [00:36:10] this. We want to [00:36:12] save yes as [00:36:13] identity C. [00:36:16] So now [00:36:17] the moment I, now [00:36:19] when I have saved this, [00:36:23] automatically [00:36:23] this nano is an application when i say nano identity dot c it opened an interface and [00:36:30] opened the file by the name identity dot c then i input the program and when i saved it [00:36:40] actually this was in temporarily available in the memory the moment i saved it it has been [00:36:48] saved into the artisan. [00:36:51] How will I know? [00:36:52] I'm asking shell. [00:36:55] My intention is I want to list [00:36:56] all the files [00:36:57] in a long format [00:37:00] and give me all the files [00:37:02] in the current directory. If I don't [00:37:04] mention any other parameter, [00:37:07] it is going to look. [00:37:09] When I see the moment I say [00:37:10] look, that means it is going to [00:37:12] read. What it is going to [00:37:14] read? It is going to read [00:37:16] the current [00:37:18] working directory [00:37:20] and [00:37:21] it will just list only the name of the [00:37:25] files. [00:37:26] Oops, there are so many files [00:37:29] in there. [00:37:30] What you wanted to see is only identity [00:37:33] dot c but you are seeing so many [00:37:35] files. So the moment I give [00:37:38] ls minus la, shell gave it [00:37:40] to kernel [00:37:41] in the language that kernel will understand [00:37:44] of what is the output expected. [00:37:47] Now the kernel is going to [00:37:48] look at the file system in this particular folder [00:37:52] what are all things available it is going to read only the file name and list it [00:37:56] where is it going to list it is going to list it on the screen [00:38:00] that means finally it is using a write function also [00:38:04] write function means there is no mention about where [00:38:08] to print by default it will print it on the standard [00:38:12] output which is my monitor in this case [00:38:15] now I can go ahead and [00:38:18] but Sundar you told me [00:38:22] that you have created a [00:38:23] directory in which we are [00:38:26] going to [00:38:27] save all our [00:38:29] programs but now [00:38:31] is it in that directory what we have created [00:38:34] present working directory [00:38:35] no [00:38:35] that means I created this file in [00:38:39] slash root wherein instead [00:38:42] I'm supposed [00:38:44] to create it [00:38:46] in the directory, the directory [00:38:49] that we have created, which directory we created, we created process call. [00:38:54] This program, what we have created [00:38:57] is supposed to be in this directory. [00:39:04] So let me move to this directory, process cell, [00:39:06] so that I won't make this mistake again. [00:39:09] Now, I want to move it from root directory [00:39:13] to the process call directory, [00:39:16] which is available under the root slash root. [00:39:20] Slash root is the home directory of the root user account. [00:39:24] So now I'm going to use the MV command. [00:39:29] MV is nothing but copy move. [00:39:32] So now what I want to move, [00:39:34] I want to move slash slash. [00:39:36] I want to move. [00:39:38] What is the file name that we have created? [00:39:41] We created identity.c. [00:39:43] Where I want to move, I want to move it to the current directory. [00:39:48] Now, ls minus la. [00:39:51] Now, the identity.c is available. [00:39:54] Now, is it available in the previous directory? [00:39:59] I'll just say identity. [00:40:00] It's not there. [00:40:04] So let us list it fully. [00:40:07] Are we able to see the identity.c? [00:40:09] No. [00:40:10] Now, this identity.c is still stored in the hard disk only, [00:40:14] but [00:40:15] the meta information [00:40:17] has been changed [00:40:19] instead of this to be associated [00:40:22] with the root slash root directory [00:40:24] it is getting [00:40:26] associated with slash root [00:40:28] slash process call [00:40:30] so if I go out [00:40:32] of this directory I will not be [00:40:34] able to either find [00:40:36] so this [00:40:38] how is it happening [00:40:40] so in this case Sundar is MV [00:40:42] a system call no [00:40:45] MV is an application that is written by or for the Ubuntu operating system. [00:40:53] So it is an application. [00:40:55] Now this application will make a system call. [00:40:57] What calls it will make? [00:40:59] It will go to that directory, that is change directory. [00:41:04] It will list all the files that is available in this directory. [00:41:08] There is a different function that is available internally. [00:41:13] But this identity.c is going to list the files, [00:41:21] is going to look at it deeper into the folder structure. [00:41:25] Now let us compile this. [00:41:28] How am I going to compile? [00:41:30] All I need to do is I need to use the GCC tool. [00:41:37] So, what I'm doing is gcc-val-vextra, that is w-extra, identity.c is a program name, and hyphen-o-identity. [00:42:02] I want to, now, I, just give me a minute, all the messages I want, okay. [00:42:14] Now, instead of showing it to me on the screen, [00:42:19] I want the GCC to compile the code and save it to a file. [00:42:24] This hyphen wo basically gives it as identity. [00:42:29] So now this compiled is going to be written into the storage device. [00:42:34] So instead of showing what is the content of the identity.c, [00:42:39] it is going to compile and write the output into the hard disk. [00:42:45] Now there are no output in the screen. [00:42:49] That means it has returned back into the hard disk. [00:42:54] How can I get to know? [00:42:55] Now identity, which is executable, [00:42:58] is available in this directory. [00:43:02] Cool. Now I can run this. [00:43:07] I can run this because it is executable. [00:43:11] Let me clear the screen. [00:43:12] I'm just going to run it with the shell as a compiled C program. [00:43:19] Now it says that process ID is 3256. [00:43:23] System is Linux. [00:43:26] Node in which it is running, the virtual machine name, [00:43:29] IIT partner 2026 autumn. [00:43:32] Release is 7.0, iPhone 34 generic. [00:43:37] And the machine architecture is x86. [00:43:39] so where did we get all these things from [00:43:43] from the program which we have written [00:43:46] okay but how did it work [00:43:50] for that let us trace it [00:43:53] you can use as trace utility [00:43:56] I'm just going to ask it to trace [00:44:00] only one thing [00:44:04] that is you name [00:44:06] that has been executed [00:44:09] by identity. [00:44:13] The moment I ask [00:44:15] S-Trace to use this, [00:44:17] now it is giving me, this utility [00:44:18] is giving me this information. [00:44:21] Process ID is [00:44:22] 3283. Which process ID? [00:44:25] The process ID which [00:44:27] identity [00:44:29] has run as a process. [00:44:32] 3283 was [00:44:33] assigned to this, especially [00:44:35] for uname. [00:44:36] Now, identity is the parent process, and identity program has called uname to know what is the name of the system, that node name, and then it also got a process ID for its only uname function, so that is 328. [00:45:00] now uname [00:45:02] system is Linux [00:45:04] node name is IT [00:45:06] and that's what it has given [00:45:07] system and node name [00:45:09] which one the uname [00:45:11] utility inside our [00:45:13] key program [00:45:14] okay rest everything is [00:45:18] same which node [00:45:19] what is the release and [00:45:22] what is the mission exited with [00:45:23] zero that means no output [00:45:26] okay [00:45:28] now [00:45:29] So when we executed this, we know that it has called for getting the process ID [00:45:41] because get process ID will get this process in which identity executed. [00:45:47] We also have uname, which will give this information. [00:45:51] We also know that it is going to call a write function. [00:45:54] So in case, if I want to trace everything, instead of just giving the uname only, I can give get PID, and I can also get the information about the write, and then enter. [00:46:13] So now if you look at it, the get PID, the get PID 3298. [00:46:24] So if you look at uname, process ID is 3283. [00:46:29] But the get PID process, because it is also an application, [00:46:34] which needs to run as a process, [00:46:37] and it will have a unique process ID, [00:46:40] and that process ID is 3298. [00:46:44] Now it calls for a write function inside it. [00:46:49] So now you can see 3298 printf. [00:46:53] 17. Then the process ID is 3298. [00:46:57] So we will be able to trace [00:47:01] the system call that our application [00:47:05] is making to the kernel. And the kernel is going [00:47:11] to give back the information to the system call. The system [00:47:15] call will give it back to our application. [00:47:19] Our application is nothing but C application which is [00:47:22] identity. [00:47:25] OK, cool. [00:47:27] So now this identity has called you name, get ID, and write. [00:47:35] And we get all the details for each of them. [00:47:39] So that means this parent has created three child processes. [00:47:44] And each of these process will have its own process ID. [00:47:48] Once the process is completed, the process ID will be released. [00:47:53] OK, cool. [00:47:55] Now, suppose an application needs [00:47:58] to save a transaction record to a file. [00:48:03] And in case if it is required, we want to retrieve it later. [00:48:07] How does that application interact with the file system? [00:48:12] Basically, application will give [00:48:16] an open call. So we are executing [00:48:20] the application. So the application is going to give [00:48:24] open function, all the functions are [00:48:28] lower cases, so let me correct it, now this [00:48:32] open function, moment it opens [00:48:36] it will get a file descriptor, because it [00:48:40] is opening a file, and every open statement will get its [00:48:44] own unique file descriptor, which is unique [00:48:47] and this file descriptor is going to [00:48:52] call the function [00:48:54] write and this [00:48:56] write function is going to write it to [00:48:58] the hard disk [00:49:00] if the request is [00:49:04] saved [00:49:06] okay [00:49:09] now Sundar we said later we wanted [00:49:12] to retrieve [00:49:14] that now the same application [00:49:16] is going to [00:49:17] retrieve so now [00:49:20] the application [00:49:21] is going to open up [00:49:24] system call which is something like a read function and this read function [00:49:33] will actually read the content from the file which is written in the hard disk [00:49:39] so once it is able to read then this will be moved to the RAM which we generally call it as [00:49:50] application buffer application buffer is nothing but a temporary space it is going to be allocated [00:49:57] from the ram and then once it has got the information we can't leave that file as is [00:50:06] if you leave that file as is then there are chances that the file can get corrupted because [00:50:11] it is still the open state so once whatever we wanted to perform once that is process is over [00:50:26] then this application buffer is going to call a system call make a system call to close the file [00:50:32] because if you want to read the file actually the read what it will do both open and read [00:50:41] opening the file because without opening the file you can't read the file [00:50:45] so this read will do both the functions open the file and as well as read the content of the file [00:50:52] it will get loaded into the buffer and once our job is done a close call will be made [00:50:59] a close call will be made to close the file just to ensure that we are not corrupting the file [00:51:07] now let us [00:51:10] quickly [00:51:11] see how it works [00:51:13] give me a minute [00:51:15] stop sharing [00:51:54] sorry guys [00:52:44] let me share it again [00:52:46] the full screen [00:52:48] sorry guys [00:52:50] so what we have done is we have understood this process [00:52:53] now let us [00:52:55] run a program [00:52:56] a C program which is going to [00:52:59] open the file [00:53:00] it will create the file [00:53:02] it will open the file it will read the file it will write the file on the screen and we will [00:53:06] follow the entire process now let me create a file and let us name it as file demo so i'm just [00:53:20] opening the this is nano is also an application i'm asking nano to open a file which is nothing [00:53:29] but file demo.c [00:53:31] and let me see [00:53:36] what is there, there are no contents [00:53:38] now nano itself is an application [00:53:40] that means in nano there is a [00:53:42] process which would have created inside [00:53:44] the Linux [00:53:46] operating system, kernel would have [00:53:48] created the process, now that process is [00:53:50] running, until I save [00:53:52] and close this application, the process [00:53:54] nano process will [00:53:56] run, so let me [00:53:58] create a [00:53:59] let me create a [00:54:02] Save, modify, prefer, right to the file name. [00:54:09] So now this is, I can see, I can give LS minus LA. [00:54:18] Now I have file demo.c as well. [00:54:21] This is another program which is going to actually create a file. [00:54:28] and if the file is not [00:54:32] existing create the file if the file is existing [00:54:34] read the file and show us the output so let me just [00:54:39] go ahead and compile this no errors [00:54:43] no output that means it has compiled [00:54:48] successfully and we do have file underscore demo [00:54:51] which the same name I asked it to output [00:54:54] so now I can [00:54:56] do this [00:54:58] I can say [00:55:00] dot [00:55:02] file demo [00:55:05] so now you can see [00:55:08] it is displaying the file descriptor [00:55:10] the moment [00:55:12] it uses the open read [00:55:14] the moment it opens [00:55:16] our read [00:55:17] there will be a unique file descriptor [00:55:20] that would be assigned [00:55:22] to this process [00:55:22] the descriptor is a numeric value [00:55:26] here in this case it is three bytes return is 25 read from file this is that transaction [00:55:36] is the content and the file descriptor closed that means this is released [00:55:43] and it is opened to write there was a file descriptor that it got opened but when the [00:55:50] file is getting closed file descriptor also is released now let us see what is there in this [00:56:00] directory we created file demo we compiled it we got an executable file demo file but [00:56:08] currently i'm seeing transaction.txt file is also there what is there in it let me just use the cat [00:56:15] command and see that is a transaction id so which what is this transaction file this got created as [00:56:25] part of our program so what is our program let me use more command let me ask it to open the file [00:56:35] demo.c basically it will show only the number of lines within the screen and it will wait for us [00:56:41] to give more input to go but anyhow it is less than one screen so it has displayed the entire [00:56:50] file so if you look at here we have used a certain flags so basically if you look at it [00:57:03] i have used o underscore create o underscore trunk o underscore read write rdwr is read write [00:57:13] read write and this is our permission 0644 the permission for the file if file is available [00:57:23] then open open which file name here the constant character file name is nothing but transaction [00:57:30] dot txt message is equal to transaction dot txt this is what exactly it got created first [00:57:37] and now if it is available then it is going to open so what is this o create what is this [00:57:45] what rank what is this o r d w r and what is this 0 4 4 4 0 6 4 4 this is o create means it is going [00:57:56] to create this file if it is not [00:57:58] existing. If it is existing [00:58:00] then it is going to open. [00:58:03] And this file name, file name [00:58:04] is nothing but referred as [00:58:06] transaction.txt. [00:58:08] When we were running [00:58:10] this for the first time, we [00:58:12] did not create this transaction.txt [00:58:14] it was not available. [00:58:16] So this system [00:58:18] call has created this transaction.txt [00:58:21] file [00:58:21] with a content [00:58:24] transaction ID. So now [00:58:28] this file has this content and that is [00:58:31] what we have seen here [00:58:33] cat transaction.txt [00:58:35] which has a transaction ID [00:58:37] transaction 1001 [00:58:38] now what is this O truncate [00:58:42] what will it do [00:58:43] this is a pipe, I will come to the pipe [00:58:45] a little later [00:58:46] this will actually truncate the file if it is [00:58:49] existing [00:58:50] it will truncate the existing file [00:58:53] to 0 length [00:58:54] and then it will create [00:58:57] the new file with this content and what is this rdwr basically it is a transaction system call [00:59:06] which is actually going to open the file in the read write mode that means this file is opened [00:59:15] for both read as well as write system calls and the permission is 0644 this is the requested [00:59:23] permission bits when creating this file do we have this in the file let us just look at this [00:59:33] ls minus la we will look only at transaction.txt now you can see zero six four the zero means it [00:59:47] indicates that it is not a directory but a file yes the first bit the second these three [00:59:54] it's six what we have said and the second and the third basically only read and read that means [01:00:05] owner can read and write others can only read and this is a type file that is what this permission [01:00:13] gives. So, when it [01:00:15] has created, it has also assigned this permission. [01:00:18] How it could assign this [01:00:19] permission, it makes a system call. [01:00:23] Okay, fine. [01:00:25] Now, we also [01:00:28] have something called [01:00:30] lseq. [01:00:34] That is, lseq, [01:00:39] what does it do? [01:00:42] After write, [01:00:44] the file offset is at the [01:00:46] end of the file. [01:00:48] So, the lseq [01:00:49] fd, 0 [01:00:51] 06 set, we are going to move it back to the [01:00:55] beginning so that the subsequent read, next time when you are reading, [01:01:00] it will read the full file. Now I am [01:01:03] reading the file cat transaction. I entered, it is [01:01:07] giving me. Now if I leave it like that without using [01:01:11] this lseq system call, the [01:01:15] pointer will be after 1001, after the [01:01:19] 1 in 1001. [01:01:22] That means next time [01:01:23] when I'm going to run [01:01:25] cat transaction, [01:01:28] it is not supposed [01:01:29] to display anything, but it is displayed. [01:01:31] Why? Because I'm moving [01:01:33] the pointer towards the starting of the [01:01:35] file. That's what this [01:01:37] 0 means, seek [01:01:39] set. [01:01:41] Set it back. [01:01:44] If it is not able to, then [01:01:45] this is the error and close the [01:01:47] file descriptor. [01:01:49] so this file descriptor is something which will be assigned like how every process is getting [01:01:55] a process id every file operations is going to get a file descriptor now let us observe the [01:02:03] kernel interaction let me clear the screen now i can give a command what are all options we have [01:02:12] done we have opened it we have read it we have displayed it we have written it all operations [01:02:18] has been done in this particular application or the program so we can use s trace s trace is the [01:02:24] linux utility and i'm going to ask it to trace what it what i want it to trace let me give [01:02:33] a read a read function of which application if i don't give the application [01:02:40] then it won't display anything [01:02:44] I need to tell which trace [01:02:49] you wanted to do for which application [01:02:52] so I'm just going to say this is what I have [01:02:56] executed, you can see [01:03:00] now it is telling file descriptor is 3 [01:03:04] this is what it is, basically it has read [01:03:08] the whole and it has given only what is necessary for us bytes return is 25 25 bytes it has written [01:03:20] read again it will read what it will read transaction id and such is the content [01:03:28] that is what exactly is equivalent to the 25 25 bytes that this 25 bytes is nothing but this [01:03:35] and read from file moment it reads from the file this is all it could display file descriptor is [01:03:46] closed because we are closing the file and it is exited with zero no errors now i can also along [01:03:55] with this i can also ask for other operations that this program has made as a system call to the [01:04:03] kernel. We know [01:04:05] we asked it to write. We know [01:04:07] that there is a [01:04:09] closed function in the program. [01:04:12] There is lseq also [01:04:13] and there is [01:04:15] openat also. [01:04:19] The moment I gave [01:04:19] it is telling for the [01:04:21] openat, look at file [01:04:23] descriptor is still 3. [01:04:26] So openat [01:04:27] is basically openat. [01:04:30] What it is going to open at [01:04:31] and it will. Then after that [01:04:33] if you look at it, close [01:04:35] 3, then [01:04:37] open at, read [01:04:39] 3, close 3. [01:04:42] So why there are [01:04:43] so many open ats? Because [01:04:45] for every function, [01:04:47] every system call that our application [01:04:49] is making, [01:04:51] it is going [01:04:52] to close. [01:04:54] The open at is coming because [01:04:56] the previous operation it has [01:04:58] closed. So now you want to [01:05:00] read the file. [01:05:01] so it is opening the file again reading the file and then closing the file so every system call [01:05:07] you are making as far as file management is concerned it is going to close at the end of [01:05:14] the system call it will not leave the file open so now why the trace may show open at rather than [01:05:24] open linux commonly implements the underlying file opening operation through open it it doesn't [01:05:34] though we are giving open function underlying system call for the open function is [01:05:42] opening the open function interface in the c library will use that system call open now [01:05:54] Now, are we able to locate the call that creates the file, [01:06:00] the call that writes the record, [01:06:03] the call that reads it, and services? [01:06:07] So the key message is file input output [01:06:12] is not just a C programming activity. [01:06:16] Our program is a C program. [01:06:19] Which is our program? [01:06:20] The program, the application what we wrote is file underscore demo. [01:06:26] this is not going to open the file directly it is going to ask kernel to open it by making a system [01:06:34] call and that system call not only open any file input output activity it is totally controlled [01:06:46] interaction between a process kernel and the file system so there are three things which is [01:06:51] getting involved one is our application which is running in the user space is going to make a [01:06:59] system call and this system call will be made to kernel and this kernel is going to respond back [01:07:11] when will it be able to respond back only after accessing the artist so this is another system [01:07:20] call within the system call now the kernel and what we are interested is this part of it [01:07:29] this part of it is we are not discussing but what will happen is from the hard disk it will retrieve [01:07:36] and then put it into the memory and from the memory it is going to respond to system call [01:07:45] how it will respond we have the file descriptor as a reference so it will refer back to that file [01:07:51] descriptor automatically our application will get connected back to respond to the system call and [01:07:58] the system call is going to respond to the application and that is where exactly we are [01:08:06] getting our output on the screen so there are three things that is getting in involved here [01:08:15] what are all those [01:08:17] see when I give enter application [01:08:19] command not found [01:08:20] perfectly fine [01:08:22] the key takeaway is [01:08:24] it is a controlled interaction [01:08:27] between process [01:08:29] which has [01:08:31] a process ID unique [01:08:33] and then [01:08:35] the kernel [01:08:36] and then [01:08:39] the file system [01:08:40] there are three things which was involved [01:08:43] this file system is nothing but your linux file system where you have folders files everything [01:08:49] stored there in the hard disk so there are three entities involved in this particular program [01:08:59] it's a small program we have entities involved in it in case if our program is going to be a big one [01:09:08] like a banking application or a travel application or tracking application of all the aeroplanes in [01:09:15] an airport those are all huge applications which will go into lacks and lacks of lines of codes [01:09:24] there also the concept is very same it's not going to change in that program if there is a [01:09:31] file open call it is going to follow the same thing but in case if it is going to open multiple [01:09:37] files at a given point of time then you will have more file descriptors three four five six [01:09:44] three seventy eight five ninety two all those are file descriptors whichever file it is handling [01:09:52] then for each activity there is going to be a process in the process id [01:09:58] and if a system call is going to call on another system call then it is a child process [01:10:05] until the child is completed [01:10:07] parent is going to wait [01:10:09] so this is the key [01:10:12] take away [01:10:13] end of the day the entire activity [01:10:16] of communicating [01:10:17] between the program [01:10:20] and [01:10:21] the resource [01:10:24] is done by the colonel [01:10:28] so that's the role of the colonel [01:10:31] and that's where [01:10:33] exactly this process [01:10:35] and system call [01:10:36] made by the application [01:10:39] is handled by the kernel. [01:10:42] Uniquely identified [01:10:43] processes and uniquely [01:10:45] identified file descriptors. [01:10:47] File descriptors, we will get [01:10:49] it only in terms of the file management. [01:10:53] Now, [01:10:58] let us get four [01:10:59] operations [01:11:00] performed. [01:11:03] And let us observe it closely. [01:11:07] We know that [01:11:08] we have used fork [01:11:11] function. We know that the fork function is going to create [01:11:16] a child process. Now [01:11:20] fork creates a processes, execute [01:11:24] does not normally create a process. [01:11:29] It changes what an existing process [01:11:32] exists. This is part of the C library. [01:11:37] part of c library we also have exit function which will close the file and exit the application [01:11:47] and that's why we are getting the prompt back once the process is completed [01:11:53] let us do demonstrate let us have that demonstration let us create a [01:12:00] c program i'm using c because it is simple to understand rather than using a big application [01:12:08] and trying to trace it a small c program very focused on the processes that we are [01:12:16] planning to understand that's why these small small programs now let me clear the screen first [01:12:25] let me create another program [01:12:28] which is basically [01:12:30] help us to understand [01:12:32] the forking [01:12:34] process [01:12:35] now let me create a [01:12:38] program [01:12:39] which is going to [01:12:42] help us to [01:12:44] understand what was the [01:12:46] ID before the [01:12:48] forking [01:12:49] this is basically before the forking is done [01:12:52] and after that once [01:12:54] you have the fork basically [01:12:57] the style process that is getting created [01:13:02] we are using get pid and get ppid [01:13:06] ppid is basically the parent [01:13:09] process id and this is the [01:13:13] process id parent process id means [01:13:16] this is the child's process id and this will get the parent's [01:13:19] process id so here all these things [01:13:23] applications get pid is a function that is being used in the c program but still it is going to [01:13:31] run in the user space only but it will create a system call and give it to the kernel which one [01:13:38] the shell shell is going to create that system call and give it to the kernel because this [01:13:44] application cannot interact with the operating system directly and that is the reason we always [01:13:54] ask, okay, I'm developing [01:13:56] an application. In which environment do you [01:13:58] want to run this [01:14:00] application? That's the first [01:14:02] question any architect will ask. [01:14:04] The reason is, once we create [01:14:06] the application [01:14:07] and we have kept Linux in mind [01:14:10] and created the key program, [01:14:13] you can't expect that [01:14:14] to run in the windows unless [01:14:16] you have a compiler that will convert that [01:14:18] to Unix-related [01:14:20] instructions. For example, [01:14:22] getpid is a Linux command. [01:14:24] Suppose if you want to run the same program in a Windows environment, then we need to [01:14:31] replace those getPID, we need to replace all those processes into some other process so [01:14:39] that Windows understands it. [01:14:42] Because Windows is also an operating system and it is also going to have a kernel and [01:14:45] kernel is the core of the Windows operating system itself. [01:14:49] So our application will open a system call and that system call will go to the Windows [01:14:55] operating system kernel. [01:14:57] Get PID won't run in Windows operating system because get PID is not a Windows command. [01:15:03] The equivalent Windows command, we need to run it in the C program and then compile it. [01:15:09] Now let us go ahead and compile this program. [01:15:13] So it has not given any error. [01:15:16] to ls minus le so we have the fork demo executable also now let us go ahead and run it [01:15:27] so now i'm just going to say run this basically fork demo i'm running in the shell shell will [01:15:37] understand make a system call to the kernel so before the forking process id is 3764 [01:15:47] now if you look at after forking [01:15:51] the parent process id is 3764 [01:15:54] and the child process id is 3765 [01:15:58] so in the program we have forked [01:16:02] means we have created a child process for a certain process [01:16:06] now the child process is 3765 [01:16:10] and the parent process id is 3764 [01:16:13] it's just the reverse [01:16:15] just that in the program [01:16:17] I just [01:16:19] return in a reverse way [01:16:21] so that the information doesn't change [01:16:23] the [01:16:24] parent process ID is [01:16:27] 3764 here also [01:16:28] child process ID is 3765 [01:16:31] so PID is 3765 [01:16:33] now [01:16:34] parent received child collected [01:16:37] now [01:16:39] once child is collected [01:16:41] it is closed [01:16:42] the parent also will close until child is closed until the process 3765 is completed this 3764 [01:16:51] is going to be in the wait status because it has nothing to do unless 3765 completes the [01:16:59] entire process and provides the input 3764 has nothing to do so it will wait but in case if it [01:17:07] has to do something in parallel and that is how we have written the code then it will continue to [01:17:12] process it. And once [01:17:14] even the parent's processes [01:17:16] are completed, it will not close the parent [01:17:18] process. [01:17:20] Assuming that the child process is still [01:17:22] running, it will wait. [01:17:24] That is the job of parent [01:17:26] ID if it has created a [01:17:27] child process. [01:17:30] Just to wait for the child process to be successful. [01:17:34] So now [01:17:34] the question comes. [01:17:36] What if the child process [01:17:38] helps? [01:17:40] Will the parent [01:17:42] continue to wait answer is yes so if your application is hung [01:17:51] that application has created a forking that means it has created a child process and the [01:17:56] child process has hung till the parent process will be waiting for a response from the child [01:18:02] process and this is where exactly we use monitoring solution to see if there are any [01:18:09] processes that are hung or running for a long [01:18:13] time, which may or may not impact the entire application [01:18:17] flow. So that information will be emailed, called [01:18:21] or paged, whatever mode of escalation we have used in the [01:18:25] monitoring solution. Then that information will reach out to our email [01:18:29] or our pager or a call itself. [01:18:34] Based on that, we will log into the system and we will check [01:18:37] if it is required we will actually troubleshoot so suppose if the child process has done [01:18:44] then we will troubleshoot the child process so that it continues to process and complete the [01:18:51] process so that it can give an indication to the parent process that i'm done so that is how the [01:18:59] monitoring of processes is going to help us to understand if at all the process is still active [01:19:05] if it is running or it is hung or it is [01:19:07] not responding [01:19:09] whatever it is [01:19:11] whatever is the case our monitoring solution [01:19:13] is going to give us that information [01:19:15] with that information we will [01:19:17] log into the system and [01:19:18] we will rectify it [01:19:20] so now [01:19:22] will we be able to predict [01:19:26] the number of processes [01:19:28] before execution [01:19:30] here we understand [01:19:33] okay parent is 3764 [01:19:35] child is 3765 [01:19:37] but will we be able to predict after a successful four there are two processes parent and child [01:19:48] but if you are the one who has written the program then you are aware of it [01:19:53] now you have written the program you have compiled and given the program to me [01:19:57] and i'm running i'm the customer to you so i'm running that application in my environment [01:20:03] now will i be able to know how many processes child processes parent processes that will get [01:20:09] created and run we can't and that's where exactly this tracing utility is going to help us [01:20:18] and to understand this do i need to understand the entire program no need [01:20:22] that's the reason we have the tools such as s trees now let us observe the system calls [01:20:30] again I'm going to use the same as trace [01:20:33] I'm going to ask it to trace [01:20:35] cloning [01:20:37] execute [01:20:38] wait and exit [01:20:41] four things I'm going to ask [01:20:43] it to trace [01:20:44] because we know that this operation [01:20:47] will call [01:20:49] this system calls [01:20:51] now the question comes [01:20:53] you know clone clone 3 and all [01:20:55] how will I get to understand [01:20:58] this [01:20:58] actually [01:21:00] it's not necessary to know all these [01:21:03] things. If you trace it [01:21:05] blank or all [01:21:06] you will get all the system calls [01:21:09] that is being made. [01:21:11] And how do I [01:21:13] get to know in the long term like [01:21:14] you need to understand the kernel of the [01:21:17] operating system. [01:21:19] What system calls it receives. [01:21:22] What are all the [01:21:23] popular system calls that an operating system [01:21:25] is going to receive. [01:21:27] In Linux it is open [01:21:28] for opening the file. [01:21:30] Is it the same for Windows? [01:21:35] It will have a different function name, [01:21:37] which the application will use. [01:21:41] So to get all those details, [01:21:42] you will have to just use the utilizing, [01:21:45] utility, whatever you have in the different operating system. [01:21:50] Now, if you look at this S-Ways-S, [01:22:01] this actually is going to follow the child request. [01:22:05] Until now, we were giving only hyphen e. [01:22:09] Now this hyphen f, [01:22:13] it is going to follow up for the child process. [01:22:17] This clone and clone 3 may appear instead of [01:22:23] system call literally named fork. [01:22:28] Basically what it does, it is actually cloning. [01:22:31] So instead of fork, [01:22:32] we'll get clone and clone 3 as the system calls. [01:22:36] and wait for will appear [01:22:39] because wait for is the system call [01:22:41] that is being made [01:22:42] by the shell for the wait function that we have [01:22:45] written [01:22:45] exit and exit underscore group is also [01:22:49] available and all this is related to the [01:22:51] fork demo that we [01:22:53] have created [01:22:53] so before the fork [01:22:56] see basically execute v [01:22:58] what to execute [01:23:00] it's a virtual environment [01:23:02] so that sorry [01:23:04] fork underscore demo is the application [01:23:06] that needs to be executed and it has executed [01:23:10] and there are 17 variables [01:23:14] now before forking [01:23:17] clone child stack is null [01:23:22] so now we can understand before forking [01:23:26] it is going to update it as null [01:23:30] what is the process id 3791 [01:23:34] this 3791 is the process id of this demo [01:23:37] now we can expect this process ID [01:23:40] 3791 is going to fork [01:23:42] now this process ID [01:23:45] 3791 is waiting [01:23:46] waiting for what [01:23:48] 3792 child [01:23:50] where the process [01:23:52] ID is 3792 and the parent [01:23:54] process ID is 3791 [01:23:56] this 3791 is going to [01:23:58] wait until this [01:24:00] 3792 is completed [01:24:02] it is unfinished [01:24:04] so the wait is still there [01:24:07] The moment it is finished, it is going to exit the group. [01:24:10] It is going to exit with, what is going to exit? [01:24:17] 3792, process is going to be 0. [01:24:19] And then this exit will be informed to the parent. [01:24:26] So now that's the reason parent got to know that child is collected. [01:24:32] And it is exiting the group with again 0. [01:24:35] That exited with 0, that means no error missing. [01:24:37] Now, when we want to demonstrate, for example, Sundari has said wait, but suppose if we want [01:24:53] to see like execute and wait, like this, we can create a simple C program and then get [01:25:06] the details of that program which you are executing. [01:25:10] strace command is good like this there are 20 25 utilities that every one of us should be aware of [01:25:21] every operating system will have this set of 20 to 20 which is related to our [01:25:29] system calls which is related to our process file management communication so we have seen how [01:25:41] how system calls are made, [01:25:45] how the processes are created, [01:25:48] process IDs are assigned. [01:25:51] And if you are using a file operations, [01:25:53] then we also understand that in addition to the process ID, [01:25:57] we will get a file descriptor which will refer to the file [01:26:00] in which it is transacting. [01:26:04] And that file descriptor will be unassigned [01:26:07] the moment the file operation is completed. [01:26:10] And for each of the file operations, [01:26:11] there will be a trace which will be available for us to understand what and how it does happen [01:26:17] so before going ahead let me stop sharing the screen and then let me see if there are any [01:26:30] queries questions from anyone okay let me see the chat first okay cool jump to the newest [01:26:40] could you please share the notes for this lecture i will definitely upload [01:26:44] the pdf with all these codes and as well as whatever explanation i have done [01:26:49] those explanations also will be available in that pdf so no worries i know it is quite [01:26:57] difficult to retain so much information at once i totally understand and this pdf will be available [01:27:04] and as far as the assignment 2 [01:27:08] I have already uploaded it has to be made available [01:27:12] to you so assignment is defined it will be made available [01:27:16] to you and I will also upload this [01:27:19] all the notes detailed notes explaining with [01:27:24] screenshot if possible I will definitely do that but without [01:27:28] screenshot I do have the document that I will be able to upload [01:27:33] This is a tracing process which we are starting. [01:27:35] Do we have something similar for already running process? [01:27:42] What we are saying, tracing is not only for initiated processes, [01:27:49] it is also for already running processes. [01:27:52] Now, the moment I executed file underscore demo application, [01:27:58] it initiated it ran it completed and after that only i'm tracing where am i tracing from [01:28:06] i'm tracing from the log the tracing will take it from the log so that means every application is [01:28:16] going to have a log at the system level and this is what we call it as system logs not application [01:28:23] logs all these are coming from the system logs so suppose if your application is running [01:28:30] continuously running then for every action every system call every process that it has created [01:28:37] from time to time everything will be available in the system log now you can use s trace is a [01:28:44] very basic utility but there are other utilities that are available which do have gui options [01:28:52] unlike s-trace here like there are tools that gives even more one level below informations [01:29:02] we can use it depends on which tool is available in your environment uh could you please help me [01:29:10] what is a system call and scheduling and context switch what we have seen is a system call [01:29:16] Scheduling and context switch is something that we are going to see. [01:29:22] We will complete it if time permits. [01:29:24] We are going to have more minutes. [01:29:26] If not, that we will continue whatever is remaining. [01:29:30] We will close it tomorrow and then get on to the next topic. [01:29:34] The one advantage is we have both two sessions in a week, [01:29:38] which will help us to not compromise on the information data. [01:29:45] quality so don't worry we will be touching upon scheduling and context switch as well [01:29:51] any other queries so okay so i do see okay varun i think you have [01:29:59] lowered your hand i see anupam anupam i am allowing your mic let me know what is your [01:30:08] question yes if you are talking then probably you are talking on mute okay can hear me [01:30:21] Yeah, now I'm able to hear you, yes, yes, right. [01:30:30] Can you hear me? [01:30:32] Yeah, I'm able to hear you, Anupam. [01:30:34] Are you able to hear me? [01:30:34] Yeah, so my question is that, like, all those logs that we, it's, like, we used to trust, [01:30:42] right, is there any limit, like, it's stored for last 30 years or something? [01:30:48] No, limit is something what we are defining. [01:30:51] by default it will have every operating system has its own default settings [01:30:56] and that default setting is don't remove logs it goes on as long as you have the [01:31:05] storage available it can store but if you want to restrict the storage utilization then [01:31:14] basically [01:31:17] we will be rotating the log [01:31:21] that means [01:31:22] we will be moving the log from [01:31:24] the current application hard disk [01:31:27] to a central storage [01:31:29] and remove it from the current storage [01:31:31] that way that log rotation [01:31:33] is going to help us [01:31:35] to move to another storage [01:31:37] and keep the live storage [01:31:40] only with a limited log [01:31:41] which is required for us [01:31:44] to troubleshoot if you want to refer the history then you can go back to the central storage [01:31:50] if you time the log and you can trace it it depends on how the architect has designed your [01:31:59] system make sense just one more question sorry to interrupt no problem yeah so if multiple users [01:32:07] are logging in the same system do they able to see the other processes like if user one has [01:32:14] run some processes with some PID? [01:32:16] If the user do log into the same system, [01:32:19] can see those processes [01:32:20] if they are logged in the same place? [01:32:24] Okay. [01:32:25] The answer is yes and no. [01:32:27] Both. [01:32:29] If you are an administrator [01:32:30] or if you are an administrator equivalent, [01:32:34] then you will be able to see [01:32:36] your processes [01:32:37] and normal user processes. [01:32:41] Both. [01:32:42] But if you are not an administrator, [01:32:44] you are a normal user, then you can see only your processes. [01:32:51] This is basically defined at the highest level in terms of access privileges. [01:32:57] So this is how it is designed. [01:33:00] For an administrator, you can see all. [01:33:02] For a normal user, you can see only yourself. [01:33:04] Or if you are belonging to a group, which is a normal user group, [01:33:10] then you can access [01:33:13] only from the processes [01:33:15] that is initiated from that group [01:33:17] depends on [01:33:19] how you have designed [01:33:20] is everyone or individual users [01:33:23] or you are part of a group [01:33:25] wherein you are getting [01:33:27] access privileges from that group [01:33:29] or if you are an administrator [01:33:31] or an administrator equal that [01:33:33] based on that [01:33:34] okay sir thank you sir [01:33:37] okay cool [01:33:41] I saw someone raising the hand [01:33:43] so they might have [01:33:44] lowered the hand as well [01:33:48] no problem [01:33:48] okay [01:33:52] I do see sir could you at least guide me [01:33:55] on how to access [01:33:56] MATLAB and other [01:33:59] Linux software [01:34:01] through IIT Patna [01:34:02] I don't have that information [01:34:05] active [01:34:07] handy with me [01:34:09] Ashish [01:34:10] let me take this curry [01:34:12] i'll check and i'll come back just a minute let me copy and paste this query so that i will not [01:34:19] use it i'll not lose it okay cool now what is the next one the next one [01:34:31] so you can contact your coordinator i'm also going to contact the coordinator to get that information [01:34:38] you can also contact [01:34:42] I will also contact and I will get you [01:34:43] if I get it before tomorrow's session [01:34:46] which is the best book [01:34:48] we discussed about this [01:34:49] actually [01:34:51] the reference is there in the syllabus itself [01:34:54] and [01:34:55] if I look at [01:34:58] what the institute [01:35:00] is suggesting [01:35:01] there are two books that has been [01:35:04] suggested by the [01:35:05] institute but I would [01:35:08] suggest there is a book by the name [01:35:12] Operating System Concept 7th edition [01:35:14] basically from [01:35:15] Wiley and Sons [01:35:16] written by Galvin, Gagney [01:35:19] and Silvershaz [01:35:21] suggested readings [01:35:23] number 1 [01:35:24] if you are able to [01:35:27] understand that book [01:35:29] then you can go to the Megra Hill [01:35:31] that is advanced concepts in operating [01:35:33] system. Don't get into the [01:35:35] advanced concepts. The third book is something [01:35:38] that i would not suggest at this point of time once you have understood the basics then there [01:35:45] is the book to be referred so i can share on the screen it is available in the table of content [01:35:58] itself cool i was referring to the serial number one suggested readings hope you are able to see [01:36:07] my screen written by galvin gagny and shibar shesh operating system concepts [01:36:15] john valley and sons it's a very good book it will take you from basics [01:36:21] okay cool now let me close this [01:36:27] please repeat the first book name again it is available i'll paste it here not an issue [01:36:34] I'll paste it here or if somebody has it [01:36:37] you can also paste it in the chat [01:36:40] I'll do that [01:36:45] let me see if I'm able to [01:36:48] it is an image [01:36:54] if I can [01:36:56] upload the image itself [01:36:59] let me see if I can do that [01:37:01] yeah I could [01:37:06] okay so Sakshan has replied back to you Ashish [01:37:14] hope you got it they also responded great so you can refer this page for the thing [01:37:23] so any other queries questions from anyone before we move ahead that just look okay [01:37:34] share some kernel commands and error debug for the kernel aditya i will do that but i need to [01:37:42] see what all the appropriate commands i will do that i'll take this as an action item for [01:37:47] myself but i'll do that don't worry great yes it will cover the basics what i am teaching [01:37:59] but some practical things what i am showing may or may not be there in the book from the [01:38:09] example perspective whatever i am teaching is more relevant and this book also will [01:38:15] not let you down for the exam. That I can [01:38:18] definitely see. Anything else from anyone? [01:38:24] Let me see. Okay. [01:38:26] Is there anyone who has raised their hand? [01:38:30] Let me see. Okay. [01:38:34] Cool. Okay. Great. I don't see anyone [01:38:38] raised. So I believe we are good. [01:38:43] Now we have 220 [01:38:45] 20, sorry, 2, 30 to, okay, great. [01:38:50] When we started, I think it was around 200, we started. [01:38:58] What do you mean by communication and the network? [01:39:03] If you're referring communication between the processes, [01:39:09] yes, that we are going to cover. [01:39:12] Network, if you're referring it to the network interface, [01:39:15] yes [01:39:18] very very important question [01:39:24] I think you need to get out of that [01:39:25] mindset [01:39:27] Vikas Kumar [01:39:28] because that's not [01:39:32] going to help [01:39:32] but I can give you one tip [01:39:35] whatever [01:39:37] assignments [01:39:38] if you have completed 1 and 2 [01:39:41] that will give you [01:39:44] an idea about how the case is going to be [01:39:46] and [01:39:47] the only thing is [01:39:49] there will be four assignments and two [01:39:52] quizzes. All combined [01:39:54] together will give you [01:39:56] important concepts that will [01:39:58] be covered in the end semester. [01:40:00] Because the way I design [01:40:02] the assignments and quizzes is [01:40:04] with appropriate [01:40:06] proportions as we move ahead. [01:40:10] So [01:40:10] that will give you [01:40:12] an indication about [01:40:13] important chapters or concepts [01:40:16] but not questions okay again i don't have any bank question bank as such every time i write [01:40:30] questions based on what we cover uh so assignment two as i said before uh it'll be opened up in a [01:40:40] up I think max by Monday [01:40:43] okay cool guys [01:40:47] so it's 9.20 [01:40:49] I was just planning [01:40:53] to take the next one [01:40:55] let us do [01:40:57] that let us do [01:40:59] a zombie process [01:41:01] and then [01:41:03] we'll close and we will take up [01:41:06] the [01:41:07] M map, M map is nothing but the [01:41:10] memory mapping and [01:41:12] break, virtually the virtual [01:41:14] memory, how it is mapping to the [01:41:16] physical memory [01:41:17] and also [01:41:19] we have the [01:41:22] demonstration for break [01:41:24] these two needs to be [01:41:28] covered and [01:41:30] the last one is inter-process [01:41:32] communication [01:41:33] so the [01:41:36] inter-process communication [01:41:38] and [01:41:40] mmap [01:41:42] we will do it tomorrow [01:41:43] and that may take like 20 minutes [01:41:46] 30 minutes and then we will [01:41:48] move towards the next concept but [01:41:50] before closing the session today [01:41:52] let us [01:41:54] understand the zombie process [01:41:56] basically let us understand [01:41:58] and confirm that the parent [01:42:00] waits [01:42:02] for the child process to [01:42:04] complete [01:42:05] let me show my screen just give me a minute [01:42:08] guys [01:42:08] 227 [01:42:11] okay great now let me down my screen entire screen [01:42:19] okay great hope you are able to see my screen now let us see the list of the files [01:42:31] okay nothing is there let me go back ls minus l here we have something called a zombie program [01:42:40] program now let me run this zombie program the moment i run here if you see the parent is sleeping [01:42:50] and child exiting now the parent is waiting to have a response from the child [01:42:57] once it receives the response from the child child will exit and parent also will exit [01:43:04] how can we see that [01:43:07] I can join the another [01:43:11] thing as long as it is running [01:43:14] so here we will see ps minus [01:43:17] oh it's closed so just a minute let me run it again [01:43:21] before running the thing [01:43:24] let me keep this ready [01:43:31] okay so now let me go ahead and run this [01:43:45] again program I'm getting on to the next [01:43:48] one i'm going to i have that i should what is happening [01:43:58] let's hope it won't process a yaw what is this ppid state [01:44:17] that is status and cmd fnp child clarity what is wrong with this okay [01:44:29] probably it doesn't have it in the program [01:44:33] let me just see, otherwise I will modify the program and you will see it tomorrow [01:44:37] oops, control X [01:44:40] I am reading the, oh, it is only showing [01:44:51] see why child is exiting, exit of 0 [01:44:55] fork is happening, now [01:44:58] print of parent sleeping, this is the else condition [01:45:04] and I am giving a sleep of 30 seconds [01:45:06] and that is where exactly it is [01:45:07] we will be able to see [01:45:10] within this 30 seconds we will be able to see [01:45:12] the PID [01:45:13] PPID both [01:45:15] I will modify this program [01:45:18] and we will get it demonstrated [01:45:19] tomorrow and we will have [01:45:22] inter-process communication also [01:45:24] between the processes [01:45:25] how it communicates [01:45:27] how it handles and how it identifies [01:45:30] we will see and then we will be moving [01:45:32] towards the next concept [01:45:34] any queries any questions from anyone before we close the session today can you assume that we [01:45:46] are good assignment to whatever we have completed until last week it doesn't cover this week [01:45:54] so whatever we have covered it is it will cover the system on process call as well [01:46:01] theoretical questions are there [01:46:04] that assignment too [01:46:06] question, sorry [01:46:08] the quiz one [01:46:09] I'll be uploading it [01:46:12] by Tuesday, Wednesday again [01:46:14] it might open up to you [01:46:16] by Thursday [01:46:17] that will cover what we are covering [01:46:20] tomorrow also [01:46:21] hope I answered your queries [01:46:25] anything else [01:46:26] from anyone before we close [01:46:28] the session [01:46:29] are we good okay great thank you so much guys have a great evening we'll meet tomorrow at [01:46:41] 2 p.m take care bye let me stop recording