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 an all related top command features and parameters can be listef 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
Start top Command
The top command can be started without any parameter of with some parameters. If you start the top command without any parameter you will see the following screen.
- 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.
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 into red.
Show Absolute 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.
Kill Running Process
The top command provides the ability to kill 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.
Set Update Interval For top Command
By default top command updates the screen and information with 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 parameter. In the following example we will set the top command update interval as 5 seconds which will be more reliable.
$ top -d 5
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