Hello, this is Dr. Miller, and this
is Episode fourteen point 14
of Assembly.
Today, we're going to write a system
call and we're going to use
integrity in order to do it.
And we're going to use both fork
and wait.
So Forkan wait system calls.
So what's our problem to be solved,
so we'd like to use Falke system
called to create two processes
and then what the child is going to
do is it's going to sleep for a
while and then the parent is going
to wait for the child to exit.
And then each of these processes
is going to print right before
it finishes.
So a couple of interesting places
you can look so you can look and
understand Falk and
understand what it does.
So Falk allows you to create two
different processes.
The ID for the parent is the child
and the ID for the child is zero.
And then we also have wait and
so wait is going to wait for a
process or a bid in order
to finish and we'll be able to see
that it takes three parameters and
we're going to have to set up those
parameters when we make our
call.
All right,
so we'll get ready for our print
statements.
So inside of here, we're going to
have the child's print statement.
And then we'll have the parent.
Putting our new lines and our Noles
inside of there, and then we're
going to print off our our child's
ID
inside the parent.
We're going to print a number, so
it's got a percent de again,
put a new line and a
zero in there
and then inside here we have
print F that's external.
And then we're also going to use the
sleep function.
All right,
so the very first thing that we're
going to do is we're going to
make our call to Facebook, also
create a couple of labels.
So I got my child
and I also got it done.
And so both the child
and the parent
will jump to done so that they don't
do that code.
All right. So if we look up the
system, call number four, Facebook,
that is the number two.
So we're going to go ahead and move
into X, the number
two.
We are then going to just call
in to Haiti. So Falke doesn't take
any arguments.
And so we can just go ahead and call
in to Haiti and then we'll
we're going to do is we're going to
look at the value for X,
so X will either have the PID
or it'll have zero.
So go ahead and compare that
to the number zero.
So jump if it's not zero
to our parent.
And then jump zero, or
you could just to jump to the
child or additionally,
because it's right after here,
we will get a follow through.
So on our child, what we'd like to
do is we'd like to do a sleep first
and then we will
go ahead and exit.
And this sleep just shows us that
the parent is, in fact, waiting for
the child.
So.
I'm going to push the number three
for three seconds, call
sleep so it allows
to sleep for three seconds, add
to E.S.P
for two, correct our stack
and we're going to move into
yak's our see,
which is that string above
call print
string to print off that string.
And then we've got our call to jump
in. Done.
All right. So the parent has a
little more work to do.
So here we are going to try and
print off that child ID so that we
know that the parent is ready for
that child to go.
So push X.
So that is the kid, right, that
we got from up here.
We did that comparison on.
So just go ahead and push that onto
the stack.
Move yak's format.
Push.
Yeah, so we push our format
and call print off
so we can print that.
We'll go ahead and correct our
stack.
And so we got
two parameters on this, we'll go
ahead and eat
to that.
All right,
and actually, we'll go ahead and do
four and then
so if I take off four,
I'll get off that printf argument
and then I want to get back that kid
that I need to wait for.
And so I'm going to go ahead and pop
SBX.
So I'm going to save that ID into
Yak's because I'm going to actually
need it.
So when we call.
Wait.
This is the bid
to wait for
OK, and then I'm going to allocate
on the stack for are
the pointer that it needs, so it
needs a pointer to
store the information about the bid.
And so we're just going to subtract
a local variable here.
So sub E.S.P
eight, put a comment
here.
Well, then go ahead and calculate
that stackers a sec pointer
to move dcx
E.S.P.
OK,
and then we we're going to have to
set our options again.
All of our elements
are going to be inside of registers.
So our options for
that call are going to be
zero. So we don't have any options.
And then we again have to look up
the function for weighted.
So that ID,
which is going to go in X, is
the number seven.
So that is weighted
and now we're ready to go ahead and
do our system call and use int
80 for that.
And then we push on a couple of
things to the stack.
So add E.S.P
eight
and then we're going to go ahead and
print that. We are done.
So we'll go ahead and move into XP,
which is that string at the top
for the parent call
print string.
All right.
So as we can see it printed off the
child's ID,
the parent waited for the child,
and then when the child finished
it, printed it, printed that it was
done, and then the parent was
waiting for that.
And so when we go into the assembly,
we can see.
So the the act of
waiting on a pad will not return
until that child has
terminated, and so the
parent will be waiting here on this
line after it's called this
in order to execute because it
doesn't have
the kid for the child.
So it waits until that that child
finishes and then it can continue
executing. So that's why we saw a
delay.
And again, if we ran it again, we
would see a new child did
it would wait for the child to be
done approximately three seconds
and then the child would finish and
then the parent would finish.
So today, we talked about using
system calls and we did both a
fork and a weight.
So looking forward, we're going to
talk about strings and see and see
how they are in assembly.
If you have questions, you can
e-mail me, Miller, M.J., you and
you. And you can find me on Twitter
at my house 30.