- [Instructor] The ps command shows you
up to date process information,
but we have to keep running it to get real-time data.
Linux has another tool used just for
displaying real-time process information called TOP.
In a terminal, start TOP by typing in top and hitting enter.
Note that the display is being
updated every couple of seconds.
In the summary area at the top of the screen
TOP shows how long the system has been up,
the load average, how many processes are running,
how many are waiting for CPU time,
the overall CPU usage, and memory usage.
We can modify this area with a few shortcuts.
Press L to show or hide the load average/uptime line.
Press number one if you want to show CPU usage
for all CPU cores if you have more than one.
Press T if you want to toggle between task and CPU states.
You can also turn this data off as well.
Pressing number one and T allows you
to have a solid bar for each CPU core.
Press M to toggle between different memory displays
or turn off memory statistics.
In the fields area, it shows the same fields as ps.
We can change these fields by pressing lower case f.
All of the current fields have an asterisk next to them.
Select and deselect fields by pressing the spacebar.
You can navigate through the list
with the up and down arrow keys.
For example, if you want to add the Parent Process ID field
we'd move down with arrow key and press the spacebar.
We can change the sort field by pressing the S key.
You'll notice on the top line,
our current sort field is now Parent Process ID.
You can move fields around by selecting them
and then pressing the right arrow key
and then moving the field to where you want it
and then press the left arrow key.
Press Q to quit the field menu.
The next section down shows the processes themselves.
We can change the data presented
in these fields just like ps.
Press C to toggle between command name and command line.
Press upper case U, followed by a user's name
to show only processes run by that user.
I'll type in grant which is my user name.
Press upper case U again
and hit enter to show all processes.
We can also scroll through the tasks
that are not on the screen using the up and down arrow keys
or the page up and page down keys.
Not only does TOP have the ability
to show realtime process information,
but it has the ability to interact with processes as well.
One of the most useful things we can do is kill a task.
Press K for the kill prompt.
We then need to choose a process ID to kill.
We can also select a kill signal.
SIGTERM is the default.
This is a very friendly way of killing a process.
If that doesn't work, we can send it as SIGKILL signal
which forcibly removes the process.
To provide a SIGKILL signal,
we'd enter the number nine when prompted for a signal.
If you want to cancel the kill prompt press escape.
We can also renice a command.
This changes the nice value of a command
which we talk about more in this chapter.
The higher the nice value, the nicer the process is
to the CPU and thus less priority it gets.
Lowering the nice value increases its priority.
To change the nice level of a command,
press R then choose a process ID.
I'm going to choose 4484 and hit enter.
Now we choose a nice level.
I'm going to choose five and hit enter.
If you want to cancel out of the
renice prompt just press escape.
A moment ago we looked at changing the sort field.
This is useful, but if you quickly wanted
to change between sorting by CPU usage
and sorting by memory usage it's too much work
to go into the menu and select a different field.
To sort by memory usage press an upper case M.
Press upper case P to sort by processor or CPU usage.
Press an upper case T to sort by
the amount of time a process has been running
and press an upper case N to sort by process ID number.
TOP has a ton of features so I encourage you
to spend more time with the man page.
Press Q to quit and then type in man top and hit enter.