Linux top Command Tutorial with Examples

Linux provides the top command in order to monitor system resources from the command-line easily. The top common provides information about the CPU, Memory, Network, Process usage in real-time by updating the information every 2 seconds. The top command is provided by default by the popular Linux distributions and there is no need to install it.

Display Help Information About Top Command

The top command provides a lot of features and options and all related top command features and parameters can be listed with the help information. The help information can be displayed in different ways. The -h parameter will show very simple help information which will list parameters.

$ top -h

More detailed help information can be gathered about the options and parameters the man page of the top command can be used like below.

$ man top
Display Help Information About Top Command

Start top Command

The top command can be started without any parameter or with some parameters. If you start the top command without any parameter you will see the following screen.

$ top
Start top Command
  • PID shows the process ID of the given process.
  • PR shows the priority of the given process.
  • SHR shows the amount of shared memory used by process.
  • VIRT shows the total virtual memory used by process.
  • USER shows the owner user of the process.
  • %CPU shows the CPU usage percentage of the process.
  • TIME+ shows total CPU times used by the given process.
  • SHR shows the Shared Memory Size in KB by the given process.
  • NI shows the nice value of the process.
  • %MEM shows the memory usage of the process.
  • COMMAND is the command which created the process.

Scroll Down the Display

A typical Linux operating system or distribution runs a lot of processes by default. When using the top command all these processes can not be displayed on a single screen and display. So we generally need to scroll down the displayed to see other processes. The Page Down key can be used to scroll down.

Scroll Up the Display

After the scroll down of other pages, we may need to scroll up to the upper screen. The Page Up key can be used to scroll up the display.

Quit After Specified Interval/Refresh Count

By default, the top command will run forever when started. It will update the screen regularly too. If you want to exit from the top command screen after a specified refresh count you can use the -n option with the number of the refresh count. In the following example, the top command will exit after 5 refreshes.

$ top -n 5

Display Specific User Processes

By default, the top command will list processes about all users. But if you want to list the processes of the specific user you can use the -u option and username. In the following example, the user named ismail processes will be listed.

$ top -u ismail

Change Text Color

The top command interface uses white and black in general. Or the background color set according to the bash and terminal configuration. But you can change these default colors by using the z key while the top command is running. This will change the color to red.

Change Text Color

Show Absolute/Full Paths of Binaries or Executables

The top command displays the process name just with the executable file name. If you need to list the absolute or complete path of the binary or executable file you can use the c key while the top command is running.

Show Absolute Paths of Binaries or Executables

Kill Running Process

The top command provides the ability to kill a process by providing its PID or process ID. While the top command is running press the k key and provide the process ID which is 12823 in this example.

Kill Running Process

Set Update Interval For top Command

By default top command updates the screen and information with a 1-second interval which can be a short interval for some cases. You can change the update interval by using the -d option and providing the seconds as parameters. In the following example, we will set the top command update interval as 5 seconds which will be more reliable.

$ top -d 5

Show Forest View

In Linux, processes are created and folder by their parent processes which creates a parent-child relationship between processes. The forest view can be used to show this parent-child relationship between processes in the top interactive screen. While running the top interactively using the V and V keys enable and disabled the forest view.

Show Forest View

Exit/Quit From Top Command Interactive Screen

When the top command is executed it will run forever unless a refresh count is not specified or exited. You can exit from the top interactive screen by using the q key.


Print top Command Version

The top command is provided by the Linux package named procps-ng . We can list the top command or procps-ng package version by providing the the -v option like below. This also provides very basic usage information about the top command.

$ top -v
  procps-ng 3.3.16
  top -hv | -bcEHiOSs1 -d secs -n max -u|U user -p pid(s) -o field -w [cols]

Leave a Comment