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