Find out how to monitor the limited resources on your system. Explore how to view and sort the usage information in this video.
- [Narrator] Every computer has a limited amount of processing power, memory and storage space. While we can sometimes increase these resources, it's important to be able to keep an eye on how they're being used and to break down what process on a system is consuming how much of each. For that, we can use the top tool. Top shows a live breakdown of each process and how much RAM, processing power and other aspects of the system's resources are being used. You can sort the view in a few ways which makes it easy to get an up-to-date view of current usage.
Let's take a look at top in a little more depth. I'll type top and we can see the basic display here. Here at the top of the display is the name of the application and the current system time. I can see how long the system has been running, in my case 10 minutes, and how many users are logged in. Right now, there's just one, just me. After that is the load average, representing how much work the system's processors have to do versus their ability to get it done. The numbers are based on 1.00 being 100% of one processor core.
0.50 means one core is at half capacity and 2.00 means either one core has twice as much work as it can handle or two cores are right at their full capacity. It's important to know how many processor cores your system has for this number to have meaning. The three different numbers represent the load over the past minute, five minutes and 15 minutes which lets you peek into the past a little bit and see if a spike is new or if it's been happening for a little while. The second line gives us a summary of the tasks or processes that are running and if any are considered a zombie process, processes that have finished running but haven't been removed from the process table yet.
On the third line, we see processor usage broken down into what user processes are consuming, what system processes are consuming, what NIST processes are consuming, that is processes that have had their priority changed, and how much of the processor's time is spent idling. We also see what amount of processor resources are being used on waiting for input/output operations, often that'll be from a slow disk and what percentage of the processor resources are being used for hardware and software interrupts. And if you're using a virtual machine, what percentage of the processor time is being used or stolen by the hypervisor.
The following line shows in kibibytes. How much memory is used or available? We have the total available, in this case four gigabytes. What amount is currently free, what specific amount is used by processes and what amount is used as a buffer or cache for the disk. And the last line in the header here shows the swap space, the area on disk where the contents of the RAM that aren't currently being used get saved or paged out to make room for other things. This system isn't doing too much so it hasn't used any of the swap space, but it shows the total available, of that how much is free, and what the used amount is.
The last column shows how much memory is still available which would be used before swap is used and we're not even close to using swap space yet here. The table view down here lets us sort the list of processes in different ways. PID here is the process ID, the number that gets assigned to a process when it starts and then goes away when the process exits and is removed from the process table. This is a shorthand for talking to the process as we'll see later with the PS command and some others. The second column shows the user responsible for the process.
System processes will run as root and you may see other users for specific processes here. Next is priority, the relative importance of the process or an indication of how likely a process is to get access to processor resources in competition with others. Priorities start at zero and go up from there, with lower numbers meaning a higher priority. The next column, NI, represents NISTness of a process or a modifier on the real priority that can be set by the user.
This scale goes from 19 to negative 20. And here, the more negative a number is, the higher priority it confers on a process because adding the NISTness value to the regular priority moves it closer to zero if it's a negative number and further away from zero if it's positive. We'll see how to change the process priority in a little bit. The next columns, VIRT, RES and SHR have to do with how much virtual memory a process is using. RES is how much physical memory a process is taking and SHR is how much shared memory it's taking.
The S column shows whether a process is sleeping, indicated with an S or running indicated with an R. %MEM shows what percentage of the processor's resources a process is currently using and %MEM shows the percentage of memory each process is using. TIME+ shows how much processor time a process has used since it started. And then finally, at the end is the command that's running in the process. Pressing the H key here will bring up a fairly spartan help menu that gives us a few tips on what keyboard commands are available here.
Depending on how you want to see the data, I encourage you to experiment with some of these. But for now, we'll use X and Y to toggle highlights and the capital R command to toggle the sort order. We'll also use the lowercase b command to toggle between bold and reverse coloring. And we'll use less than and greater than to change the sort criteria. I'll press Q to leave the help and let's toggle the highlight from bold which is pretty subtle here to inverted so we can see what's active a lot easier. The lowercase b command does that.
The lines that are inverted here are active or running tasks. And if we press the X key, we can see a highlight on the column that that information is sorted by. The Y key toggles a highlight on running tasks. I'll press Y and I'll press Y again. We can use less than or greater than to sort these columns, moving right with greater than and left with less than. I can change the sort order of these columns with capital R.
And when I'm done using top, I can quit with the Q key. You can also explore what processes are using IO or input/output, transfer of data to the disk, with a program called iotop. It's not installed by default, but you can install it easily from the Distro's Package Manager. And you can get some insight about how much network activity is going on with iftop, bmon, nethogs or a variety of other tools from the repositories. You can manage the quotas that groups or users have available to them in order to limit the access to resources like the number of active processes or logins or how much data they can use by editing the etc/security/limits.conf file.
Top gives us a good overview of how processor and memory resources are being used on the system. Once you become familiar with it, it'll become an invaluable tool for keeping an eye on activity and a suite of other tools are able to give you a look at how other resources like disk and the network are being used. In combination, these tools give you the ability to track down resource-intensive processes if you need to.
- Booting the system
- Managing the startup process
- Updating software
- Understanding shared libraries
- Examining resource utilization
- Upgrading or adding hardware
- Exploring system log files
- Scheduling and verifying tasks
- Incident management