How to Check Memory Usage on Linux Terminal



RECOMMENDED: Click here to fix Windows errors and optimize system performance

How can I check used and free RAM usage on Linux operating systems using command line and GUI tools?

Linux comes with several sets of commands to check memory usage. The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The vmstat command reports information about processes, memory, paging, I/O blocks, traps, and processor activity. Finally, you can use the top, and/or atop/htop commands, which provide a dynamic, real-time view of a running system. top and friends can display summarized information about the system and a list of tasks currently managed by the Linux kernel.

Under Linux, there are commands for almost everything, as the GUI is not always available. When working on servers, only shell access is available and everything has to be done with these commands. So today we will review the commands that can be used to check memory usage on a Linux system. Memory includes RAM and swap.

It is often important to check memory usage and memory used per process on servers so that resources are not exhausted and users can access the server. For example, a Web site. If you are using a web server, it must have enough memory to serve visitors to the site. Otherwise, the website would become very slow or even crash during peak traffic simply because there is not enough memory. It’s just like your desktop PC.

Use the Free Command

However, sometimes the tip may be a little too high for your needs. You may just need to see the amount of free and used memory on your system. The free command is available for this. The free command is displayed:

  • Total amount of free and used physical memory
  • Total amount of swap memory in the system
  • Buffers and covers used by the core

Launch the command from your terminal window. This command is not issued in real time. Instead, you get a snapshot of the free and used memory at that moment.



September 2021 Update:

We now recommend using this tool for your error. Additionally, this tool fixes common computer errors, protects you against file loss, malware, hardware failures and optimizes your PC for maximum performance. You can fix your PC problems quickly and prevent others from happening with this software:

  • Step 1 : Download PC Repair & Optimizer Tool (Windows 10, 8, 7, XP, Vista – Microsoft Gold Certified).
  • Step 2 : Click “Start Scan” to find Windows registry issues that could be causing PC problems.
  • Step 3 : Click “Repair All” to fix all issues.

download



Of course, you can make free a little more user-friendly by adding the -m option, like this: free -m. This will allow you to specify the memory usage in MB.

If your system is modern, even remotely, you will of course want to use the -g (gigabyte) option, as in free -g.

If you need amounts of memory, you can add the t option like this: free -mt. This simply adds up the amount of memory in columns.

Use the vmstat command

To view memory statistics using the vmstat command, you can use it as follows:

vmstat -s 

The flag provides detailed statistics on memory usage.

In the output, you can display the free memory and the input of the free swap memory, which indicates the available memory in your system.

Check process memory usage with pmap

The pmap command allows you to check the memory of a process or set of processes in a human-readable format (in KB or kilobytes). All you need to know is the PID of the processes whose memory consumption you want to check.

For example, suppose you want to check how much memory the process uses with PID 917. To do this, run pmap as follows:

$ sudo pmap 917

As you can see, the total memory used by the 917 process is 516104 KB or kilobytes. You can also see here the amount of memory used by the libraries and other files that are required to run the process with PID 917.

Checking memory usage under Linux using the ps_mem command

ps_mem is a simple Python script that allows you to accurately determine the main memory usage of a program running under Linux.

This can determine how much RAM is used per program (not per process).

It calculates the total amount of memory used per program, sum = sum (private RAM for program processes) + sum (shared RAM for program processes).

Calculating shared RAM is problematic, and the tool automatically selects the most accurate method available for the kernel being executed.

Conclusion

This guide provides several options for checking memory usage on your Linux system. We have learned that one command provides a wealth of valuable data for future analysis. It is important that you learn how to interpret the information correctly.

Now you can manage your server more efficiently.

5 Commands for Checking Memory Usage in Linux


RECOMMENDED: Click here to troubleshoot Windows errors and optimize system performance