Get To Know Linux: See Your Systems' Memory Usage - gHacks Tech News

Get To Know Linux: See Your Systems' Memory Usage

If you are new to Linux you might be wondering how you can find out how much free memory your system has or how your memory is being used. For this there are two simple to use applications: top and free. The top application informs you what tasks are running and how much memory and? CPU? is being used by each. The free application tells you how much total RAM is being consumed by your system. Both are command line applications and both do an outstanding job of reporting information.

Naturally both commands have gui front ends (gnome-system-monitor does both), but what do you do when you have a headless server? Or what about when you are logging in remotely and you can't tunnel X? In those instances you will want to be able to get this information via the command line. And Linux has the tools for you.

Free

The free command displays the amount of free and used physical and swap memory on your system. Free has a limited number of switches to use which makes the command even simpler to use. The switches are:

-b Displays the output in bytes

-k Displays the output in kilobytes (this is the default action)

-t Adds a line at the bottom which contains the totals

-m Displays the output in megabytes

And that's it.

When you run free the output will look like:

total ? ? ? used ? ?? free ?? shared ? buffers? cached
Mem: ? ? ? ??? 884 ? ?? ? 862??????? 22???????? 0?????? 289 ? ? 127
-/+ buffers/cache: ? ? ?? 445 ? ? ? 439
Swap: ? ????? 3992 ? ? ? ?? 0 ? ?? 3992

So you can see the total (in megabytes) memory being 884 and the free being 22. Depending upon your setup and what you have running you might think free is wrong. One thing you have to keep in mind is the buffers and cached memory are actually still available so in the above example the total used memory does include both the buffer and the cached memory. So often there is more memory available for application use than you would think. This gets very confusing because the used memory listing includes memory used by the kernel that may or may not be used for various modules (such as networking, sound, etc). There is another issue confusing memory usage. Since a vast number of Linux applications share libraries (like libc) those libraries could already be in memory when you launch an application. Huh? Let's try a simple explanation.

You have Application A and Application B that both use Library 1. Application A reports it uses 25 MB of memory to run and Application uses 25 MB of memory to run. But Library 1 takes up 5 MB of memory to run. If Application A is already running that means Library 1 is already running so you can subtract the Library memory from the total of Application B.

So you can see how complex memory usage is for Linux. Which is why you want to also check out the command top.

Top

The top command diplays running Linux tasks. The information it offers is:

  • PID - Process ID
  • USER - The user who ran the command
  • NI - The nice level of the process
  • VIRT - Virtual memory the process is using
  • RES - Resident (non virtual) size of memory
  • SHR - The amount of shared memory a task is using
  • S - Process status
  • %CPU - The percentage of the CPU the process uses
  • %MEM - The percentage of memory the process uses

So you can see there is plenty of information to be had from top. The point is, between the two applications you can summize the amount of memory being used at any given time.

Gnome System Monitor

GNOME System Monitor
GNOME System Monitor

As I said earlier, there are gui tools for this tasks. One of those tasks is gnome-system-monitor. It gives you every bit of information you need, and does so in a much more easy to use/read format. When you open up this tool you will see, after a bit of poking around, it gets its information with a little help from both free and top. Take a look at this application to see just how well the information is used and displayed.

The image to the left highlights the resource listing tab of gnome-system-monitor.

Final Thoughts

It's pretty easy to see how complex monitoring memory can be with Linux. Fortunately there are plenty of tools to aid in you in this task. Although it's not always easy to get a cut and dry snapshot of what memory you have available, you can get good idea of where your memory is.

Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. Rupert said on March 11, 2009 at 12:51 am
    Reply

    I’ve always preferred htop to top. It’s just got a nicer interface, but is still command line ;)

  2. Geek Question Answer said on December 28, 2010 at 8:13 pm
    Reply

    Thanks for the post!!

    If you could post how to check Memory used by process that will help more.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.