In this lesson, we're going to walk
through how the troubleshoot processes
within the Linux system.
Now, during your operation
on the system might encounter various issues
that degrade the performance,
and it makes the system unusable.
So common cases are process hangups causing instability
that a process consuming too many resources,
making the system sluggish in general.
So we're going to go through
and learn how to identify these processes,
Figure out the current states that they should be in,
like running interruptible sleep,
uninterruptible sleep, zombie mode,
different ways to kill processes and view them.
So let's get started.
Now, the first command we're going to go over,
is the process command.
Now by default, what it does is,
it identifies the current processes,
that's running in this shell by the user, okay?
So right now, we always know Bash is the default shell
for this Linux distribution.
So that's always going to be running in the background for us.
And that process command is what we just executed.
Now, if you see, that has a process ID,
and this is going to be vital when it comes
to identifying services, killing processes,
changing priorities, things of that nature.
Now, in order to see everyone's process,
we can use the dash e option,
and that's going to show us all the processes
that are currently running on the system.
Okay, we see there's a lot of them running,
and again, practice with the less command.
We want to see it from top to bottom.
Remember, there's our systemd there, always the first one.
And each process always increments one after the other,
of course, starting with the first in it,
which going to be systemd for us.
Sometimes there'd be a situation
where you don't actually know the process ID.
To quickly do it use the P grep command.
And so, for example, we're going to use sshd.
That's going to be the secure shell daemon, quick command,
enter the process that we're looking for,
and it's going to spit out the process ID.
Now there'll be times where you're running process
typically as script,
and you need to run that process in the background,
meaning that it's not going to consume,
the entire commands line screen, okay?
So we're going to use the ampersand symbol
at the end of the command,
and that's going to allow it to go into the background.
And now we're going to use the sleep command,
just to see this happen, right?
So we're going to do sleep,
300 seconds ampersand,
okay?
So it spits out the process ID for us,
and we're going to run this process just
to see that it is actually running.
Okay, now, as mentioned earlier,
we're going to learn how to kill processes,
and we'll use the kill here,
just to end this command.
Okay?
Going to run this again.
And we see that that process was terminated, okay?
Another useful command that we can use is the top command.
And what this does is, it's like an interactive prompt
to allow us to see all the process's memory consumption,
and CPU consumption.
It's usually going to be the most important and vital.
And here, we're also able to change the nice values,
which coordinate with the priority of the process.
So, we're going to check this out.
We're going to use the uppercase M,
and that allows us to sort everything
by the amount of memory that is taken up.
So you see the top one is the shell that we're running.
That's consuming the most memory currently.
And then we also can do capital P,
and that's going to sort things by the CPU process,
whatever's running the highest CPU process.
Currently, not a lot of things are running.
A lot of things are very,
using very minimal CPU process.
But in a enterprise environment,
there will be a lot of processes running,
and some will consume the CPU and memory heavily.
List of lsof, it shows us a list
of the files that are currently being ran,
and the processes that are running them, okay?
So again, let's try to see this
from the top and we can see the command process ID, user,
we get the name of the file that's being open, et cetera,
a lot of get useful information about this one.
Again, remember, this is all relative
to the files that we're trying to open
because it can be situations where you're unable
to open a certain file that you're trying to,
and it's because of processes hogging
up the particular object.
As we saw earlier, that systemd,
that's the initial boot process.
Now, we're going to use this again for the analysis.
We're going to analyze the boot order, okay,
and we see this command.
It's mostly going to be used with the blame command,
and that's to see how long it actually takes
for all the processes to run it.
So it, by itself, just gives us how long the startup takes,
and that's for us to identify any performance issues.
But when we do it this way, we add the blame,
it gives us all the services
to go see how long it took them to start, okay?
This will definitely be useful,
when we're troubleshooting any type of booting up process.
All right, next, we're going to go through,
and learn how to modify the priority of systems.
Now, typically, the scheduler is pretty effective
at scheduling and prioritizing processes
that need to be ran in a certain order.
But again, it'll be time where we want
to increase the priority,
and let the system know, Hey, we want this done first.
And so we want to use this command really quick, xl,
and it's going to give us the priorities run by the user,
and it shows the nice values of them.
By default, the nice value is going to be zero,
and the lower the priority,
the lower the number, the higher the priority.
And it's going to range from negative 19 to 20.
So, anything with negative 19,
it's going to be first, and 20 will be last,
and anywhere in between.
Okay, so we're going to simulate a long-running process,
switch bit,
and this command is just going to be an iteration of copies.
Okay, so, we see the process ID, 15, nine, four, seven,
15, nine, four, seven.
We want to use the sudo top command,
'cause we want to change the nice value of this.
Okay?
So, we're going to go in here, and do R.
And going to do 15,
nine, four, seven.
Okay.
And we're going to change this value to negative 15.
A little quick.
I'm going to look here, see if it went through for us.
Okay, so we see I had that folder,
taken care of,
and again,
pretty much as soon as we got,
as soon as we changed that nice value,
you can see at the bottom, how it says, done.
Now, with quick processes, our, our CPUs are there so fast,
that they can get done with copy processes pretty quickly,
but changing that priority really amped it up.
And so that's going to just indicate that, hey,
we were able to copy the Etsy folder
into a backup directory very quickly.
Okay, so we went over how to troubleshoot certain processes
by identifying the process IDs, how to kill them,
how to run processes in the background,
and how to change the priority that the scheduler uses
for processes when we're running commands
on our Linux system.
Thank you for sticking with me through this walkthrough,
and I'll see you in the next lesson.