Home Download Ubuntu

How to use top and htop commands to monitor cpu and memory usage in Ubuntu

1.top command

The top command displays information on your Ubuntu system, running processes and system resources, including CPU, RAM & swap usage and total number of tasks being run.

Once launched, top stays running, displaying statistics in real time. Processes are listed by their process ID number, along the name of the command that started the process. The statistics are sorted via these categories.

Example of code:


The column are:

PID: A process’s process ID number.

USER: The process’s owner.

PR: The process’s priority. The lower the number, the higher the priority.

NI: The nice value of the process, which affects its priority.

VIRT: How much virtual memory the process is using.

RES: How much physical RAM the process is using, measured in kilobytes.

SHR: How much shared memory the process is using.

S: The current status of the process (zombied, sleeping, running, uninterruptedly sleeping, or traced).

%CPU: The percentage of the processor time used by the process.

%MEM: The percentage of physical RAM used by the process.

TIME+: How much processor time the process has used.

COMMAND: The name of the command that started the process.

To exit top, press "q".

1.htop command

Htop is an ncursed-based process viewer similar to top, but it allows to scroll the list vertically and horizontally to see all processes and their full command lines.
Tasks related to proccesses (killing, renicing) can be done without entering their PIDs.

htop is much easier than top. For example: to kill a process you need to scroll down with arrow keys to select a process and press F9.

Command line for htop is:


You may need to install this one if it doesn't launch:

sudo apt-get install htop

Resources: Official Website, jonathanmoeller, howtogeek


Post a Comment