[Autogenerated] So now we're gonna move on from this specific script and
we're going to take a look at a slightly derivative function that we have
here and that is this process resource monitoring script and what we'll
see at the very beginning here is that we're still using the create
process list function because we're still going to be basing it off of a
process list.
But in this case,
what we're going to be doing is we're going to be monitoring the
resources that are currently being used by the top x number of
processes whatever you specify it.
So in this case, go down here a little bit,
we'll see,
we're going to be paying attention to the top 10 of them
and specifically we're going to be paying attention to
two different resource types,
the CPU percentage that is being used by specific processes.
And then the second table that we're going to see is the memory utilization.
So as it's written right now,
it's going to take one second loops over of the different
utilization that exist for each one of the processes that
exist on this specific system.
And it's just going to reprint that every time you look at it,
if we run this, we'll see that every second is going to update.
And then the top list right now it says that Well,
obviously I'm using python on this system,
there's it's a test system.
So there's nothing else running on it.
But it's using 24,
almost 25% of the CPU and right now everything else is in order
of what processing resources they're using.
But obviously those processing uses are less than .00%.
But they still are ordered.
And the second list we have here is similar information,
but instead of being sorted on the processes that are
using the most processing resources,
these are the processes that are using the most memory resources.
So in this case to no one's surprise,
code is using the most amount of memory and that includes
not only one but five different processes of code that are
using a decent amount of memory, especially when you added up.
But the one that is using the most memory is the one with the process I.
D of 3096.
And then that list is sorted strictly on the memory amount that is allocated.
So now that we see what the output of that is.
How do we do that?
We'll see here at the top of it.
We set everything inside a try just in case we have an exception as
well as if you wanted to exit out of that loop,
you would just need to do a control C or a break and it
would softly grab that exception.
So it doesn't end up giving you a trace dump and then we sit inside a wild loop.
One of the modules that we are using for this specific module that we
didn't in the earlier ones was one called Pretty table.
And as you would imagine, it allows you to print a table in a pretty way.
And we are not using any amount of its extensive capabilities.
We are just using a simple table.
But you can format information in a number of different ways.
So if we look down here so what this part does is it spawns off a
specific instance of a pretty table and puts it into the variable
process CPU table and the variables that you see here.
The P I.
D.
The process, Name and status.
That would be the top of the table.
We create two different variables for the top CPU and top memory processes.
And then in this little loop we create the list of those
processes that we are looking for.
So one would be the top processes that use the most amount
of CPU percentage and the top processes that are using the
amount of memory resources,
then we take that information and sort them in a descending order.
That's what this fourth one is.
And then here up to that point it would be a longer list than 10.
So we only want to display 10.
And that's what this last little call out is showing
the top CPU list with a colon.
10.
So only show me up until 10 of the list.
So that the top 10 users.
So now if we moved down on this a little bit more,
this would be the actual creation of the table except for the headers and
that is this piece so it grabs each one of these variables.
So this is the process I.
D.
The name, status and so on.
Of that specific process that it has inside that variable and
it creates a new row in that specific table.
And this illiterates based on the processes and CPU person variables
that exist in the top CPU top 10 CPU variable.
So it's iterating on those processes that were returned by the earlier logic.
So by the end of this logic we have a list in table format
of all of the different processes that are using the most
amount of processing resources.
Now the second part of this is basically the same thing
except we're substituting in for memory.
So the titles are the same.
This logic is very similar but in this case we're going to be
sorting it based on the top memory users.
And the last thing we do here is we're going to clear the screen
since we're in a loop every time we print it,
we wanted to have a new screen.
So this is just running CLS since this is a Windows machine.
If this was a Linux machine, you could substitute in clear instead of C C L.
S.
And then the last two was that Prince those two tables
as we saw with the initial output.
Once we display it we're gonna wait 1 2nd which is what the time sleep does.
And then we're going to rerun all this logic all over again,
re create the list, and we're going to do that every second.
So now that finishes us up for this demonstration,
and let's move into our summary.