Monitoring memory usage on a Linux system is essential for ensuring optimal performance and diagnosing potential issues. Here are six easy ways to check memory usage on Linux:
- Using the free Command: The free command displays information about total, used, and free memory on your system, including both physical and swap memory.
free -h
This command will show memory usage in a human-readable format, making it easy to interpret. - Using the top Command: The top command provides real-time information about system resource usage, including memory usage. It displays a dynamic view of processes and their resource consumption.
top
Pressing “Shift + M” while top is running will sort processes by memory usage, making it easy to identify memory-intensive processes. - Using the htop Command: Similar to top, htop is an interactive process viewer that provides a more user-friendly and customizable interface for monitoring system resources, including memory usage.
htop
htop allows you to scroll through processes, filter by memory usage, and easily kill or renice processes. - Using the vmstat Command: The vmstat command reports virtual memory statistics, including memory usage, swap usage, and paging activity.
vmstat
By default, vmstat will display overall memory statistics since boot. You can specify an interval and a count to get periodic updates. - Using the cat Command with /proc/meminfo: The /proc/meminfo file contains detailed information about memory usage on the system. You can use the cat command to display its contents.
cat /proc/meminfo
This will output a list of memory-related statistics, including total memory, free memory, and memory used for various purposes. - Using the ps Command to Summarize Memory Usage by Process: The ps command can be used to list processes along with their memory usage. You can sum up memory usage across processes to get an overall view of memory consumption.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
This command will list the top processes by memory usage, showing their process ID, parent process ID, command, percentage of memory usage, and percentage of CPU usage.
These six methods provide a variety of options for monitoring memory usage on Linux systems. Depending on your preferences and requirements, you can choose the one that best suits your needs, whether you prefer a simple command-line interface or a more interactive and visually appealing tool.