Navigating the ‘top’ Command in Linux

0

When checking out Linux systems (or even troubleshooting computers running other operating systems), I frequently use the top command to check out the system’s RAM and CPU utilization. It provides me with information to assess the computer’s overall health. I learned about the top command early in my Linux journey and have relied on it to give me a quick overview of what is happening on servers or other Linux systems, including Raspberry Pi. According to its man page, the top program provides a dynamic real-time view of a running system. It can display system summary information and a list of processes or threads currently managed by the Linux kernel.

I often need A quick overview to determine what is going on with the system in question. But there is so much more to the top command than meets the eye. Specific features of your top command may vary depending on whose version (procps-ng, Busybox, BSD) you run, so consult the man page for details.

To launch top, type it into your terminal:

$ top

Running processes are displayed below the table heading on the top screen, and system statistics are shown above it.

Press the Z key to change the color of the output. I find this makes the output a little easier on the eyes. Press the 1 key to see a graphical representation of each CPU core on the system. Press 1 repeatedly to assess core statistics for your CPU cores.

You can display memory usage graphically by invoking the top command and then pressing the m key.

Useful top options

If you’re looking only for the processes started by a specific user, you can get that information with the -u option:

$ top -u 'username'

To get a list of idle processes on your system, use the -i option:

$ top -i

You can set the update interval to an arbitrary value in seconds. The default value is three seconds. Change it to five like this:

$ top -d 5

You can also run top on a timer. For instance, the following command sets the number of iterations to two and then exits:

$ top -n 2

Locate a process with top

Press Shift+L to locate a process by name. This creates a prompt just above the bold table header line. Type in the name of the process you’re looking for and then press Enter or Return to see the instances of that process highlighted in the newly sorted process list.

Stopping a process with top

You can stop or “kill” a running process with, too. First, find the process you want to stop using either Shift+L or pgrep. Next, press K and enter the process ID you want to stop. The default value is whatever is at the top of the list, so be sure to enter the PID you want to stop before pressing Enter, or you may stop a process you didn’t intend to.

top results
Image by: (Don Watkins, CC BY-SA 4.0)

Top top

There are many iterations of the top command, including htop, atop, btop, and ttop. There are specialized top commands, too, like powertop for power usage and ntop for networks. What’s your favorite top?