Last updated on December 2nd, 2019 at 08:04 pm
When it comes to managing busy Linux servers every Linux administrator needs to know how much load server is having and how they can Check Memory Usage on Linux, for example, if you are running a webserver you must have enough memory to entertain your website visitors so it is very important to know which service is eating more memory, as a Linux admin you must know How to check memory usage in Linux so you can run your Linux box at an optimal level.
Commands to Check Memory Usage In Linux
- The top command
- The /proc/meminfo file
- The free command
- The vmstat command
- The htop command
The top command
Top command is installed on almost all Linux distributions and its used to print Memory and CPU usage of system, it gives an excellent overview about processes, like how much a processes is utilizing system memory and cpu.
If you look at highlighted one, which is mysql server deamon taking 2.7% of memory and 0.3% of CPU. Whereas in header of below output you can see KiB Mem and KiB Swap enteries showing free and used memory resources
Related Articles :
- How to Setup Network Service in CentOS 8 / RHEL 8
- Automate the Backup on Linux Server with Bash Script
- Bash Script for My Sql & Website Automatic Backup on Linux
- Never Ever Run these Command on Linux – Must Read
The top command’s output is continuously updated, which allows you to monitor all the processes in real-time. But what if you want to show output for one processor?
Show only one process with top on Linux
To monitor specific process in linux using top command you should know the PID number of the process, then use the -p flag to specify it. In above picture we highlighted mysql process whic has PID 1595, now keeping above example in mind, lets monitor mysql process only:
In case if you don’t know PID, so you can search by name also:
The /proc/meminfo file
We can also check memory usage information in linux by directly reading /proc/meminfo system file. This is a virtual file, which means its not real file but it contains real-time, dynamic information about the system.
Now you know where other commands gets memory info? yes some tools uses /proc/meminfo system file to read memory information.
The free command
An other simple and easy to use way to check memory usage in linux is using free command, which is a most widely used command. This command is used to check information about the memory usage by your system. Here is the command you will enter in the Terminal:
In above command -m switch shows memory usage in MB and if you use -h it shows human-readable output
The vmstat command
The vmstat command with the -s option, shows the memory usage statistics much like the proc/meminfo file. Here is an example
The htop command
This is similar to top command, but it gives more detail information of cpu and memory usage.
htop may not be installed by default, so youc an install using below command on CentOS/RHEL
If using Ubuntu
To run htop command
The header on top shows cpu usage along with RAM and swap usage with the corresponding figures.
This guide provided several ways to check the memory usage in Linux system using command line. We learned that a single line command provides valuable data for analysis on system performance.
Now you can administer your Linux servers more efficiently.