• news
  • pics
  • linux
  • windows
  • proxmox
  • game
  • news
  • pics
  • linux
  • windows
  • proxmox
  • game
Home
linux

5 Commands For Checking Memory Usage In Linux

The Linux operating system includes a plethora of tools, all of which are ready to help you administer your systems. From simple file and directory tools to very complex security commands, there’s not much you can’t do on Linux. And, although regular desktop users may not need to become familiar with these tools at the command line, they’re mandatory for Linux admins. Why? First, you will have to work with a GUI-less Linux server at some point. Second, command-line tools often offer far more power and flexibility than their GUI alternative.

Determining memory usage is a skill you might need should a particular app go rogue and commandeer system memory. When that happens, it’s handy to know you have a variety of tools available to help you troubleshoot. Or, maybe you need to gather information about a Linux swap partition or detailed information about your installed RAM? There are commands for that as well. Let’s dig into the various Linux command-line tools to help you check into system memory usage. These tools aren’t terribly hard to use, and in this article, I’ll show you five different ways to approach the problem.

I’ll be demonstrating on the Ubuntu Server 18.04 platform. You should, however, find all of these commands available on your distribution of choice. Even better, you shouldn’t need to install a single thing (as most of these tools are included).

With that said, let’s get to work.

top

I want to start out with the most obvious tool. Thetop command provides a dynamic, real-time view of a running system. Included in that system summary is the ability to check memory usage on a per-process basis. That’s very important, as you could easily have multiple iterations of the same command consuming different amounts of memory. Although you won’t find this on a headless server, say you’ve opened Chrome and noticed your system slowing down. Issue the top command to see that Chrome has numerous processes running (one per tab – Figure 1).

Figure 1: Multiple instances of Chrome appearing in the top command.

Chrome isn’t the only app to show multiple processes. You see the Firefox entry in Figure 1? That’s the primary process for Firefox, whereas the Web Content processes are the open tabs. At the top of the output, you’ll see the system statistics. On my machine (a System76 Leopard Extreme), I have a total of 16GB of RAM available, of which just over 10GB is in use. You can then comb through the list and see what percentage of memory each process is using.

One of the things top is very good for is discovering Process ID (PID) numbers of services that might have gotten out of hand. With those PIDs, you can then set about to troubleshoot (or kill) the offending tasks.

If you want to make top a bit more memory-friendly, issue the command top -o %MEM, which will cause top to sort all processes by memory used (Figure 2).

Figure 2: Sorting process by memory used in top.

The top command also gives you a real-time update on how much of your swap space is being used.

free

Sometimes, however, top can be a bit much for your needs. You may only need to see the amount of free and used memory on your system. For that, there is the free command. The free command displays:

  • Total amount of free and used physical memory
  • Total amount of swap memory in the system
  • Buffers and caches used by the kernel

From your terminal window, issue the command free. The output of this command is not in real time. Instead, what you’ll get is an instant snapshot of the free and used memory in that moment (Figure 3).

Figure 3: The output of the free command is simple and clear.

You can, of course, make free a bit more user-friendly by adding the -m option, like so:free -m. This will report the memory usage in MB (Figure 4).

Figure 4: The output of the free command in a more human-readable form.

Of course, if your system is even remotely modern, you’ll want to use the -g option (gigabytes), as in free -g.

If you need memory totals, you can add thet option like so: free -mt. This will simply total the amount of memory in columns (Figure 5).

Figure 5: Having free total your memory columns for you.

vmstat

Another very handy tool to have at your disposal is vmstat. This particular command is a one-trick pony that reports virtual memory statistics. The vmstat command will report stats on:

  • Processes
  • Memory
  • Paging
  • Block IO
  • Traps
  • Disks
  • CPU

The best way to issue vmstat is by using the -s switch, like vmstat -s. This will report your stats in a single column (which is so much easier to read than the default report). The vmstatcommand will give you more information than you need (Figure 6), but more is always better (in such cases).

Figure 6: Using the vmstat command to check memory usage.

dmidecode

What if you want to find out detailed information about your installed system RAM? For that, you could use the dmidecode command. This particular tool is the DMI table decoder, which dumps a system’s DMI table contents into a human-readable format. If you’re unsure as to what the DMI table is, it’s a means to describe what a system is made of (as well as possible evolutions for a system).

To run the dmidecode command, you do need sudo privileges. So issue the command sudo dmidecode -t 17. The output of the command (Figure 7) can be lengthy, as it displays information for all memory-type devices. So if you don’t have the ability to scroll, you might want to send the output of that command to a file, like so: sudo dmidecode –t 17 > dmi_infoI, or pipe it to the less command, as in sudo dmidecode | less.

Figure 7: The output of the dmidecode command.

/proc/meminfo

You might be asking yourself, “Where do these commands get this information from?”. In some cases, they get it from the /proc/meminfo file. Guess what? You can read that file directly with the commandless /proc/meminfo. By using the lesscommand, you can scroll up and down through that lengthy output to find exactly what you need (Figure 8).

Figure 8: The output of the less /proc/meminfo command.

One thing you should know about /proc/meminfo: This is not a real file. Instead /pro/meminfo is a virtual file that contains real-time, dynamic information about the system. In particular, you’ll want to check the values for:

  • MemTotal
  • MemFree
  • MemAvailable
  • Buffers
  • Cached
  • SwapCached
  • SwapTotal
  • SwapFree

If you want to get fancy with /proc/meminfo you can use it in conjunction with the egrep command like so: egrep –color ‘Mem|Cache|Swap’ /proc/meminfo. This will produce an easy to read listing of all entries that contain Mem, Cache, and Swap … with a splash of color (Figure 9).

Figure 9: Making /proc/meminfo easier to read.
Previous article 这才是真正的“越南最美女孩”
Next article How to Use the dig Command on Linux

therock

25 Comments

  1. keto pot roast
    July 7, 2021 at 5:11 am

    diet soda keto

  2. keto diet pills
    July 7, 2021 at 1:54 am

    beans on keto diet

  3. keto diet recipes pinterest
    July 6, 2021 at 10:16 pm

    keto for women over 50

  4. completely free dating service
    June 24, 2021 at 9:09 am

    free transexual dating website

  5. 100 free dating site europe
    June 24, 2021 at 1:16 am

    free asian women dating sites

  6. south africa free dating
    June 23, 2021 at 7:34 pm

    free dating websites uk

  7. dating websites free trial
    June 2, 2021 at 8:51 am

    totally free adult sex dating

  8. free dating sites minneapolis
    June 2, 2021 at 4:18 am

    free usa dating site

  9. scotland dating sites free
    June 2, 2021 at 1:55 am

    free ts dating sites

  10. 100% free messages dating site
    June 1, 2021 at 7:41 pm

    free online dating worldwide

  11. legal online pharmacies in the us
    May 29, 2021 at 9:52 am

    legal online pharmacies in the us

    5 Commands For Checking Memory Usage In Linux – rock funs

  12. cialis next day delivery
    May 26, 2021 at 1:44 am

    cialis next day delivery

    5 Commands For Checking Memory Usage In Linux – rock funs

  13. how to buy from canadian pharmacy
    May 25, 2021 at 4:56 am

    how to buy from canadian pharmacy

    5 Commands For Checking Memory Usage In Linux – rock funs

  14. no prescription female cialis
    May 25, 2021 at 2:40 am

    no prescription female cialis

    5 Commands For Checking Memory Usage In Linux – rock funs

  15. adipex online pharmacy
    May 25, 2021 at 12:11 am

    adipex online pharmacy

    5 Commands For Checking Memory Usage In Linux – rock funs

  16. buy cialis online overnight shipping
    May 24, 2021 at 10:22 am

    buy cialis online overnight shipping

    5 Commands For Checking Memory Usage In Linux – rock funs

  17. cialis ontario no prescription
    May 21, 2021 at 12:14 am

    cialis ontario no prescription

    5 Commands For Checking Memory Usage In Linux – rock funs

  18. how to get cialis samples
    May 20, 2021 at 11:27 pm

    how to get cialis samples

    5 Commands For Checking Memory Usage In Linux – rock funs

  19. free sex dating london
    May 20, 2021 at 9:41 pm

    online dating sydney free

  20. free zambian dating sites
    May 20, 2021 at 9:38 pm

    free toyboy dating

  21. free dating agencies uk
    May 20, 2021 at 6:09 pm

    transexual free dating sites

  22. good free dating sites yahoo
    May 20, 2021 at 12:54 am

    free polygamy dating

  23. totally free senior christian dating sites
    May 19, 2021 at 9:19 pm

    free safe online dating sites

  24. viagra vs cialis
    May 15, 2021 at 5:22 pm

    viagra vs cialis

    5 Commands For Checking Memory Usage In Linux – rock funs

  25. Green Heart Tinder
    May 15, 2021 at 3:10 am

    Green Heart Tinder

    5 Commands For Checking Memory Usage In Linux – rock funs

Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Categories
  • game
  • linux
  • news
  • pics
  • proxmox
  • windows
Recent Posts
  • proxmox7.3直通显卡
  • Proxmox VE 直通显卡方案及解决N卡Code43
  • Linux系统出现:You have new mail in /var/spool/mail/root 的原因及解决办法
  • debian系统解决中文乱码
  • pve添加git和pvetools
Recent Comments
  • EdgarTot on proxmox7.3直通显卡
  • Ashvem on proxmox7.3直通显卡
  • Tedvem on proxmox7.3直通显卡
  • Jackvem on proxmox7.3直通显卡
  • Miavem on proxmox7.3直通显卡
Archives
  • March 2023 (1)
  • December 2022 (4)
  • November 2022 (6)
  • April 2022 (1)
  • February 2022 (5)
  • January 2022 (2)
  • December 2021 (3)
  • November 2021 (1)
  • October 2021 (2)
  • September 2021 (1)
  • August 2021 (1)
  • July 2021 (8)
  • June 2021 (14)
  • May 2021 (2)
  • April 2021 (2)
  • March 2021 (10)
  • January 2021 (4)
  • December 2020 (4)
  • November 2020 (13)
  • April 2020 (276)
  • March 2020 (1)
  • June 2019 (5)
  • May 2019 (10)
  • December 2015 (1)