This Article is to check the memory usage on Linux with 6 different commands. But why do we need to check the memory usage?
Now when our Desktop or a Server hang’s up, not working like get’s freeze. Then the Desktop support or Admin teams always check the usage of CPU and RAM (Memory).
Whether the usage has increased? What was the process at that time due to which our Server or Desktop gets hanged?
So in Linux, lots of commands to check the usage of Memory. In this article, we will use 6 basic commands of Linux.
- free command.
- check the file meminfo with the cat command.
- vmstat command.
- top command.
- htop command.
- atop command.
How to use the free command to check the Memory Usage in Linux.
free command in Linux to check the total, available memory or RAM. Total RAM or memory in our system, used and free space of the memory or RAM.
$ free -h
The output of the ‘free -h’ is in the human-readable format. Want to learn more about the free command in Linux refer to the link. Also, you can study the detailed parameter on the same link.
Check /proc/meminfo file with cat command.
Let’s use the cat command to check the memory usage in Linux.
$ cat /proc/meminfo
The Output is showing in KB’s and has more detail with many parameters than any other command.
How to use the vmstat command to check Memory Usage on Linux.
vmstat command is to get the information about the processes, memory, CPU, disks and etc.
$ vmstat -s
So the vmstat has some of the following parameters,
So these parameters are showing us the used memory, free memory, and swap memory.
Also, the amount of memory that is active and inactive has all these parameters output in KBs.
This command is not by default installed in your System or servers.
For CentOS and RHEL distro: $ sudo yum install sysstat
For Ubuntu and Debian distro: $ sudo apt-get install sysstat
How to use top command to check the memory usage
The top command is to display the Processes that are running on our system. The Linux top command program provides a dynamic real-time view of a running system.
If you want to learn the explanation of the output for the top command, follow the referred link.
So from the above output, you can see the current memory usage on the system.
But are you able to identify the usage statistics? the answer is NO. Let’s do that in a human-readable format.
$ top -E g
How to check the memory usage via htop command in Linux
htop command is to track the real-time processes. It is the same as the top command but it allows us to scroll up and down.
So with the help of htop command, you can track Memory Usage, CPU usage, CPU Process, and PID (Process ID).
Suppose you want to sort the processes by Memory Usage then use -s option with htop command.
$ htop -s MEM%
So the above command shows us which process is using more memory. We can also use the “M” key to sort by memory.
But the htop command is not there by default on the system. So let’s see “How to install htop command in Linux“.
How to use atop command to check the memory usage on Linux.
The atop command is an advanced system and process monitor tool, which is used to monitor the process of CPU, Memory, Disk, and Network.
But this command is also not there on the system by default. So you can refer to How to install atop command in Linux distros.
Refer the link if you want to download the atop of any other distributors.