Hello and welcome!
In this video session we will see some examples of exactly and exactly functions.
Let's begin with executive function.
We have two programs in this folder program p1 and p2 dot c.
Let's open individual programs.
So this is the first program P1 dot c.
And let's open the second program.
So we have two programs here.
The upper half is P2 dot c and the lower half is P1 dot c.
As you can see here from P1 dot c we are calling the Execve function.
This is a library function.
And here we are calling the executable of program two.
And then we are passing the arguments.
So here arguments is an array of character.
So our args contains the arguments that needs that can be passed on to the P2 program.
And here if you see this line will not be printed when we execute the P1.
This is because the exec replaces the current program virtual memory with the new program's virtual
memory.
And once the P2 has been loaded on the memory, this program runs and it begins its execution from the
main.
And it prints this line and then it prints the argument.
So this argument will be from the the argument passed from the P1 dot.
See.
So here the argv holds this these arguments.
And as a note we should always end this arguments with a null.
So let's compile individual dot c files and then execute it.
So as a note p2 should be compiled and stored as p2.
So now let's compile each dot c files p1 dot c minus p1 in the same way.
Let's compile p2 dot B2C and its name it as P2.
So here B2C is compiled as P2.
This is because from the P1 dot c, we are calling p2 as the object file of p2.
Now first, if you run uh p2 separately, it's on P2 separately.
So if you see we have got some arguments here.
We can see.
Let's pass some arguments.
S1S2.
So here this is R0R1R2 for p2 program.
So we have r0 r1 r2 for p2 program.
So now if the same thing if we run via P1.
So if you see here the main program P1 dot c is run.
Using this we got this P1 dot c.
Then I am a new program called by Execve.
So we got this line.
This is because it has called P1 has called x, x, y and the virtual memory of P1 has been replaced
by P2.
Hence we got this line as a print from p2.
And if you note here r v of zero, r v of one and r v of two, these are the parameter that has been
passed from the P1 program.
R1, r2 and r3 followed by null.
So this line is not printed here.
So if you see this line is not printed.
This is what we had discussed in the previous video session that if x v r is success then it doesn't
return.
Uh, if it fails, then it returns minus one.
Now let's see the next set of examples.
As a note, uh, before this, if you want more information on this, we have to type uh.
Man x y.
So x v manual pages are here.
This is the x v function syntax.
It takes the path of the new program and the uh arguments basically.
And we need to include the unistd.h as required.