There was a problem loading the comments.

Memory Usage Commands in Linux: A Comprehensive Guide

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Monitoring memory usage in Linux is crucial for system performance and troubleshooting. Here are some essential commands to check and analyze memory usage effectively.

 

1. Using grep to Detect Out-of-Memory Errors

The grep command helps search system logs for out-of-memory errors:

grep -i -r 'out of memory' /var/log/

Use case: Identifies memory exhaustion issues from logs.

 

2. Using free -m to Check RAM Usage

The free command provides real-time memory usage details:

free -m

Output includes:

  • Total, used, and available RAM

  • Swap memory details

3. Using sar for Historical Memory Usage

The sar command displays memory usage trends over time:

sar -r

Use case: Useful for diagnosing gradual memory leaks.

 

4. Using top -c to Identify Memory-Intensive Processes

Monitor running processes and sort them by memory usage:

top -c

Tip: Press Shift + M to sort by memory usage.

 

5. Using mysqladmin proc stat for MySQL Memory Analysis

Check MySQL queries that may be causing high memory usage:

mysqladmin proc stat

Use case: Identifies slow or stuck queries consuming RAM.

 

6. Using grep to Analyze Website Access Logs (For cPanel Servers)

Monitor suspicious access patterns that may lead to high memory usage:

grep -ir "05/Mar/2025:10:20" /usr/local/apache/domlogs/

 

Signs of abuse:

  • High requests from specific IPs

  • Excessive HTTP POST requests

  • Repeated failed login attempts

Final Thoughts

Efficient memory monitoring and optimization can prevent crashes and enhance system stability. Use these commands to diagnose and fix memory-related issues proactively.


Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting