Now we will see example of exactly system call.
Now let's open the first program.
Program one dot c.
And let's open the second program as well.
Let's open it within the same window.
So now we have two programs.
The top is the program two and the bottom half is the program one dot c.
So in this case x v is the system call which is used here.
And as a note um on top of V the other library functions such as x x x x x v are implemented.
So the main um use of v is we can change the environment of the second program.
So in this case let's have a have a look how it works.
So the exec v calls the required parameter for program two.
And then it also sets some uh argument variable and the environment variable.
So here uh env vec is the uh character uh array uh which holds uh pointer character pointer.
This is basically an array to character pointer.
And similarly argv is an array to character pointers.
So we pass argc as the second parameter which is nothing but this uh arguments and then env vec which
is an environment vector.
And we pass it as the third parameter.
As a note, we should always have a null in the end.
So now uh arg v of one is the uh Program to object file that we are passing.
So we need to pass our program to.
Object file.
As a part of the uh argument we argv for uh program.
And once the program.
Two is called here we have this program in memory.
So the program one, uh, virtual memory will be replaced by this program two virtual memory.
And we get executing program two and here we print the argument.
This argument here will be will correspond to this here.
Welcome to LSP will be the argument which we pass and it will be passed here.
And then the environment uh, we print here.
So the environment here will correspond to the environment that we pass here.
So one of the main use case of xkb is when we have to work with the environment variables, or when
we have to pass new environment variables to the new, uh, program, then we can use it.
Let's have a demo on this.
Let's, uh, compile this and run and see the output to understand better, let's compile each of the
programs separately.
GCC program one dot z minus object file gcc c program one.
So in the same way, let's compile program two dot c.
Now we have compiled both the programs.
Let's say we run program two first and see what is the output.
And let's pass some parameter param one.
Param two.
Let's see the output.
So if you see here what is happening is the param one.
And param two are taken as the parameter here.
So r v of zero will be this one argv of one is this param one argv of two is nothing but this one.
So if we execute program two initially this is the output.
So the program two has its own environment variable variables.
This is discussed in one of the previous video session.
Now this corresponds to this program.
So we are printing the argv in a loop that we have passed here, and we are printing the environment
variable here.
So this prints the environment variable.
We have a um external environment which can be used and we can print the environment.
So this prints the environment in this format uh the value and the key format.
So now if we run the same program using program one, let's run this using program one and pass program
two as the uh arg v argv of one points to the path where program two object file is stored here.
So if we pass this let us see the output.
Now if we run this the environment variable of program two is being replaced by the environment.
What we have passed in the program one here.
So the new environment of program two will be this what we have passed all the old environment of the
program two is being replaced by the new environment that is being passed from the program.
One and these are the, uh, command line arguments that is passed to program two via program one.
So this is the command line arguments.
Okay.
So let's have a small look on the manual pages of this as well.
So let's go here.
In order to open the manual page of exactly we have to type man space two space Z.
So we get this here z.
So unistd.h needs to be included.
And this is the uh path of the second program, uh, object file where in which it will be replaced
by the program once, uh, virtual memory will be replaced by this new program.
And this is the, uh, argument, uh, command line argument for the new program.
And this is the environment list of the new program.
So this is what we have used here