Join Scott Simpson for an in-depth discussion in this video Process management: top, part of Linux Tips Weekly.
- [Instructor] On a Linux system, it's helpful to be able to see what processes are running and how many resources they're using. While we can look at the processes and even find out some resource information with the ps command, there's another program called top which gives us up to the second information about resource usage. I'll run the top command here, and as you can see there's quite a bit of information that it presents. Here at the very top is the name of the program followed by the server's local time and then a listing of how long the system has been up, that is how long since the last boot.
After that comes a listing of how many user sessions are active on the system, and then a listing of the load average. This shows how much work the processors are being asked to do, over the past minute, five minutes and 15 minutes. On the next line we see some information about running tasks or processes. Right now there's 169 total here for me, one of them's running and 168 of them are sleeping which means they're loaded and have resources allocated to them but they're not actively processing anything. After that are stopped and zombie tasks.
On the third line we see a breakdown of CPU usage for the system. First is the percentage of usage by user processes and then the percentage usage by system processes. Ni or nice here refers to the percentage of CPU time spent running niced processes, those which have had their priority manipulated to be more or less important than they ordinarily would be. Idle is how much of its time the processor has spent not doing anything, and wait shows how much CPU time has been spent waiting for io or input output operations to complete.
High numbers here can point to slow or overburdened storage. And following that are percentages of processor time spent servicing interrupts and time given back to a hyper visor if you're using a virtual machine. The fourth line shows the breakdown of memory. The total is the full amount of ram the system has, and then we can see how much of that in kilobytes or rather kibibytes is free, used and how much is being used as a buffer or cash for disc operations. Below that is some information about the swap, the space on disc where things in memory can be stored if more memory is needed.
And the blank line here is used to show the response to some commands. The section that takes up most of the screen is the listing of processes running on the system. The first column PID is the process ID, followed by the user that started each process. Then comes the priority of the process and the nice value, if there is one. Niceness modifies the priority of a process to control the balance of resources that a process has compared with the others. Virt lists the amount of virtual memory that a process is using. Res is the amount of resident memory, and SHR is the amount of shared memory.
The S column lists the state of a process. S in this column means that a process is sleeping. R means that it's running, and there are a few other values as well which you can read about in the man pages for top. After that we see the percentage of the CPU resources, a process its using. And then the percentage of memory resources being used by the process as well. Time plus shows how much cumulative processor time a process has used since it was started. And command is the base command that's running in each process.
Your system will show different processes than mine, but they should be generally similar. There's a handful of helpful keyboard shortcuts that make working with the top display, a little bit more flexible. The first one I want to show you is x, or lower case x, which turns on a highlight. I'll press it a few times here. And we can see that the highlight here changes the boldness of the CPU column, which is useful because when we type less than and greater than, we can change which column is being used to sort.
I'll move around here, left with less than and right with greater than. I'll move over to the PID column, the first column. And I can reverse the sort order of a column with capital R. Lower case r lets you renice the process to change its effective priority on the fly. Capital H changes between showing tasks and threads. Capital and lowercase E cycle through the orders of magnitude that the memory is displayed in, for the overall system and for individual processes respectively.
Capital V switches to forest view, where you can see the processed trees and you can scroll up and down with the arrow keys. There are a lot of other keys that change the display, which you can see if you press h for help. You can switch the CPU and memory displays to little bar charts and turn them off with t and m respectively. You can change column justification and more. Take a look through the man pages too for a deep dive into what some of the other features are, and for a look at the command line options available to you.
Updated
2/19/2019Released
10/3/2017Note: Because this is an ongoing series, viewers will not receive a certificate of completion.
Share this video
Embed this video
Video: Process management: top