fbpx
Black Friday limited time 25% of on our life-time plans using code: LMT25
  • 00Days
  • 00Hours
  • 00Minutes
  • 00Seconds
Search
Close this search box.

8 Quick Essential Ways For Checking Memory Usage in Linux

Checking Memory Usage In Linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

To manage a server based on Linux, system administrators as well as developers should check memory usage in Linux. Proper memory management avoids slowdowns, memory leaks, and caused crashes allowing the system to be stable and fast under different workloads. Memory, or RAM, is a finite resource. Understanding the way it is used often can contribute a lot to how your system performs. You can optimize resources, keep an eye on memory-heavy processes, and avoid problems before they spread all over the system just by checking memory usage regularly.

In this article, we will go through eight realistic methods for checking memory usage in Linux with simple commands and tools. You will learn how to check the usage of memory by a process in Linux and get insight into how much specific memory has been used up by specific applications. At the same time, we will discover how CyberPanel makes memory monitoring and resource management easiest for you to keep your Linux system running smoothly. CyberPanel is a well-known control panel for web hosting with embedded tools that monitor memory usage and resource usage; therefore, users can monitor, manage, and optimize their servers with ease.

Whether you need to troubleshoot problems, optimize application performance, or scale up, these steps will give you the toolset to effectively manage your memory usage on Linux.

Prerequisites For Checking Memory Usage In Linux

To execute these steps for checking memory usage ensure that you have the following

  • You should have administrator or root access to the Linux system to run some system-level commands.
  • You are expected to have some familiarity with the Linux command line, as most of the memory checks would become easier to do.
  • Tools. Some of the techniques described below require special tools such as top, htop, or free for more profound information. Most Linux distributions have them pre-installed, but if not, installing them is a trivial task.

Monitoring Memory Utilization on Linux with CyberPanel: In case you run your server on CyberPanel, access is built into the control panel to help in monitoring memory utilization in Linux and analyzing other performance statistics.

Importance of Checking Memory Usage In Linux

It is important to check the memory usage in Linux for several reasons. A few are mentioned below:

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

Prevent Slowdowns: Excessive memory use can easily bring about an efficiency slowdown. The application might become slow or take some time to respond. Monitoring memory usage would help avoid slowdowns while in use.

Detecting Memory Leaks: When applications consume memory without releasing it, it slowly results in memory exhaustion. Periodical checkups on this aspect ensure early detection and thwart crashes and instability.

Optimizing Application Performance: Monitoring helps set memory using the application’s needs. This ensures that applications run efficiently without wasting system resources.

Avoiding Out-of-Memory Errors: When exhausted, Linux may terminate processes forcibly, an inconvenience. Memory checking will ensure managing the resources a step ahead of time to avoid errors relating to out-of-memory.

System Stability: In most cases, stability is required. Stability is even more so when the environment is in production. It monitors these memory issues and keeps them from occurring and causing system shutdown or crashes.

Scaling Plan: The trend of memory usage is important for administrators to know when to scale the system. Mostly, the scaling will avoid bottlenecks in the future because the system can handle the increasing demands.

Security improvement: Abnormal usage of memory can point out security threats like malware. Therefore, monitoring of memory helps detect suspicious activity and safeguards the system against unknown processes.

Improving User Experience: Memory usage may degrade the user experience for an application or website. Ongoing monitoring of memory permits the possibility of faster load times with more responsive applications.

Troubleshooting: Memory data are critically important in the diagnostics of performance problems. Reduction of causes becomes easy; thus, people can debug quickly and efficiently.

Optimize Resource Allocation: Resource allocation across processes or virtual machines becomes possible with efficient monitoring of memory; conflicts between services are avoided, and resource utilization is maximized.

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

8 Ways For Checking Memory Usage In Linux

1. free Command

The free command in Linux is one of the most basic commands for checking memory usage in Linux; it is extremely common and summarizes the usage of memory within a system very quickly, capturing the total as well as used and free memory, along with swap space.

free command
output

Explanation: Whenever executed, it provides a look at memory in human-readable terms as well as in raw numbers. This enables system managers to immediately ascertain whether the required amount of available memory is satisfied, or if the system will run low soon.

Options:

  • -h: Shows the memory counts in a human-readable format (for instance, MB or GB)
  • -s [seconds]: Updates the memory statistics every [seconds] so that you can keep up with the activity continuously
  • -t : Include swap memory in the total memory

2. top Command

top is a real-time system monitor, showing you information about running processes, including how much memory is being used up by processes. It is helpful when you need a dynamic, constantly updating view of what system resources are in use. It shows memory under the summary section and will also give you detailed stats regarding processes and their memory usage.

top command
output

Explanation: This top command gives an idea about which processes are using the memory. This provides you with real-time tracking about which processes are eating how much of the system resource in terms of memory.

Options :

  • -u [user]: Processes owned by a particular user.
  • -p [PID]: Processes for a particular process ID(PID).
  • -d [seconds]: Sets the number of seconds between updates. (default is 3 seconds).

3. vmstat Command

The vmstat command provides information on the performance of the system. This command contains virtual memory statistics, CPU usage, system processes, and more. It gives a view of how memory is being used, and the amount of swap space, among other important system metrics.

vmstat command
output

Explanation: The command is useful for diagnosing problems regarding memory allocation, swap usage, and CPU performance. It provides an in-depth view of how memory is being utilized with the system activity.

Options:

  • -s: Gives a summary of memory statistics, such as how much memory is used in swapping.
  • -a: Displays detailed memory statistics, showing active and inactive pages.

4. ps Command

The ps command is quite good for checking the memory usage of a particular process in Linux. It only gives you information about what’s running on your system, including its memory usage.

ps command

Output:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND

root      1165  5.0  2.3 1023456 183904 ?      Sl   10:15   1:52 /usr/bin/python3 /usr/sbin/sshd

user1      842  4.2  1.1  56000  9000 ?      S    10:25   0:10 /usr/bin/python3 my_script.py

user2     3241  3.0  0.5  37256  4708 ?      S    10:22   0:08 /bin/bash /home/user2/some_task.sh

...

Explanation: Filter processes by memory utilization, PID, or user so that you pinpoint the specific process that is consuming a lot of memory.

Options:

  • -e or -A: Shows all running processes
  • -u [user]: Filtering by specific user
  • –sort: This command sorts according to memory, CPU, etc.

5. htop Command

htop is an interactive version of the top with a more user-friendly and colorful interface. You can use it to monitor system memory or resource usage interactively with finer granularity than the top.

htop command
output

Explanation: htop provides an intuitive interface for monitoring system resource usage in real time. You can scroll through processes, sort them by memory usage, kill a process, and even perform other operations without needing to leave the htop environment.

Options:

  • -u [user]: Restricts it to displaying only those processes of a certain user
  • -d [seconds]: updates time delay, default is 1 second

6. smem Command

The smem command is similar to ps but with much more memory information like proportional memory, which counts shared memory. So, it gives a more realistic view of the number of memory every process is using.

smem command
output

Explanation: The smem command displays memory usage in such a manner that shared memory is counted only once, thus making it easier to gain insight into the amount of memory consumed.

Options:

  • -r It will print memory usage recursively to look for how deep the memory consumption per process .
  • -s Tells dstat to sort the processes by memory usage.

7. dstat Command

One of those versatile tools would be dstat, which gives a system-wide overview, including memory and CPU, disk and network usage. Thus, the monitoring of several resources in the system becomes easy and helps you to understand more clearly how they interact.

dstat command
output

Explanation: When you need a broad view of the system’s resource usage over time, dstat would be very useful, as it continues to refresh and format memory and other statistics for your ease of readability.

Options:

  • -m: Displays memory usage.
  • -c: Displays CPU usage.
  • -r: Reports swap usage.

8. watch Command with /proc/meminfo

Although memory-related in nature, the watch command combined with /proc/meminfo provides a constantly updated view of system memory. It is useful for real-time monitoring of the memory status of the system right from the /proc filesystem.

watch command
output

Explanation: The /proc/meminfo contains detailed information about system memory. To view updates in real time, you can use the watch command on the file shown above.

Options:

  • -n [seconds]: It specifies the refresh interval in seconds by using watch command. With default value, it is 2 seconds.

Other Ways To Check Process Memory Usage In Linux

Following are the other ways for checking memory usage in Linux:

1. sar Command (System Activity Report)

The sar command is from the sysstat package and gives historical information on the consumption of system resources. Such includes memory. You can apply it to the analysis of system activity, and make use of it for monitoring memory usage, CPU usage and I/O statistics.

sar command

Output: 

Linux 5.4.0-42-generic (hostname)  11/12/2024  _x86_64_    (4 CPU)

12:00:01 AM  kbmemfree  kbmemused  %memused  kbbuffers  kbcached  kbcommit  %commit  kbactive  kbinact  kbdirty

12:00:02 AM     50000     163840     76.52      12000     24560     40960     21.76     115200    34000    2400

12:00:03 AM     49900     163900     76.56      12100     24600     41000     21.77     115300    34010    2420

12:00:04 AM     49800     163950     76.60      12150     24620     41100     21.78     115400    34020    2450

12:00:05 AM     49700     164000     76.64      12200     24640     41200     21.79     115500    34030    2470

Options:

  • -r : Displays statistics regarding memory.
  • -f [filename] : Reads from a particular log file. It can be used when working on historical data.

2. memory Command

This memory command provides a simple statistical overview of the resources in terms of how much memory was used, available, or free. Some of the Linux distros carry it by default, and others need to be installed.

memory command
output

Explanation: It is meant for fast memory checks and easy-to-read summaries of the system’s memory status. Excellent when you just want a brief snapshot of memory usage but not too much detail.

Options:

  • -h: the memory summary in human-readable format, in megabytes or gigabytes.

3. nmon Command

nmon – Nigel’s Monitor – is a system resource monitor, even of memory. It offers more of a graphical view compared to classic tools like top command.

The tool is interactive and able to show more than one system metric: memory usage, CPU utilization, disk usage, etc. Long-term monitoring can be performed by this utility, too.

nmon command
output

Options:

  • -m: Boot time switch to start the monitor in memory mode.
  • -f: Writes the data to a file for later use.

4. meminfo Command

The meminfo command lets you browse extensive memory information directly from a /proc/meminfo file, similar to using the watch command with /proc/meminfo, but it is structured with a more natural view of memory.

meminfo command
output

Explanation: This command provides more information about memory usage on a detailed level about memory allocation, how much swap is used, and free memory by reading directly from /proc/meminfo file. It’s extremely useful for deep diagnostics of the system.

Best Methods of Tracking Memory Usage in Linux

Memory usage must be tracked so that it can be maintained at the best possible levels on a Linux system. Here are some working techniques for tracking memory usage:

Use Basic Commands: Some basic commands, such as free and top, are very useful for making quick measurements of memory usage and finding resource-intensive processes.

Track Swap Space: Monitor swap memory utilization as high swapping may be a sign of problems of a memory kind that should be solved

Use Graphical Tools: Use graphical memory monitoring tools so that you can more graphically view the memory usage of your system: you will be able to point out trends and problems easily

Process Analysis: Use the Processes tab in resource monitoring tools to view statistics concerning process memory usage and activity.

Stay Informed: Participate in the developer communities at Stack Exchange and keep learning recent techniques on memory management; for example, best practices concerning the memory limit and resource allocation within your system.

Role of CyberPanel in Memory Management

CyberPanel

CyberPanel is a very rich web hosting control panel,  which helps server administrators monitor and manage their systems and memory usage. Also, you can integrate CyberPanel with the free, top, htop, and many other tools for resource monitoring through their interface. Additionally, CyberPanel lets you have easy-to-read system metrics on using memory so that you can track trends to identify any issues before they begin affecting your performance. Further, it enables you to set server configurations, restart services, and troubleshoot memory-related issues so that you can have an optimized server in terms of running at perfect performance.

With CyberPanel and real-time monitoring in addition to comprehensive resource management tools, you can be sure your system is efficient and responsive. So, you avoid the impact of memory bottlenecks on your web hosting services.

FAQs on Checking Memory Usage In Linux

1. How to check memory usage in Linux?

You can use commands like free or top for checking memory usage in Linux. While the free command gives a total, used, and free memory summary, the top displays a dynamic, real-time view of memory usage and processes.

2. Which commands are good at checking memory usage in Linux?

Some of the best ways for checking memory usage in Linux include:

– Free for a quick overview.
– top or htop for real-time memory monitoring.
– vmstat for performance stats
– ps for the detailed process memory usage.

3. How to find memory usage in Linux?

You could get an idea about the usage of the memory by using free -h for human readable format or even top to achieve a more interactive result. You can use vmstat to know the usage of memory and CPU collectively.

4. How do you check the memory usage of a process in Linux?

Use the ps command with option -o to display memory-related stats, in order to check memory usage of a process in Linux specifically. Here’s an example: ps aux –sort=-%mem lists processes by memory usage.

5. How do you get the command to check your process memory usage in Linux?

There is a utility called top command, which you can use to check real-time process memory usage. Or you can use htop an interactive version with added user-friendliness while showing details on the memory usage of each process.

6. How can I check process memory usage in Linux?

To determine how much memory some particular process occupies, you can use the ps command with ps aux or ps -p [PID] -o %mem,vsz,rss. The first shows the percentage of memory used, virtual memory size, and resident set size.

7. Can I check memory usage in a particular process on Linux?

Sure thing. We can do it by the top command, for example, with the -p option to specify the process ID; or we can use ps -p [PID] -o %mem directly to check the memory usage of an individual process.

Culmination: Learning Master of Memory Management in Linux for Optimal Performance

Summing up, checking memory usage in Linux in an efficient and healthy Linux system is an easy way with commands like free, top, and ps, and more advanced with tools like htop and vmstat. That way, you can very quickly pinpoint some troublesome resource-hungry processes before they slow down or even crash your system.

Take Control of Your System Now! Monitor your Linux system’s memory usage now and begin to optimize it to have more long-term reliability.

Hasib Iftikhar
I'm Hasib Iftikhar, a dedicated technical writer at CyberPanel, joining the team in July 2024. With three years of extensive experience in content writing, I specialize in copywriting, article writing, guest posting, affiliate content writing, and SEO. My expertise ensures that each piece of content I create is engaging, informative, and optimized for search engines, helping businesses enhance their online presence and reach their target audience effectively.
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!