{"id":3041,"date":"2025-04-15T12:32:07","date_gmt":"2025-04-15T12:32:07","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=3041"},"modified":"2025-04-15T12:32:08","modified_gmt":"2025-04-15T12:32:08","slug":"real-time-memory-monitoring-in-linux-with-free-m-and-watch","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/real-time-memory-monitoring-in-linux-with-free-m-and-watch\/","title":{"rendered":"Real-Time Memory Monitoring in Linux with free -m and watch"},"content":{"rendered":"\n<p>When your Linux system starts slowing down, the <strong>first suspect is usually memory<\/strong>. Is RAM maxing out? Is swap being used? Is some process eating up everything?<\/p>\n\n\n\n<p>Luckily, Linux offers simple yet powerful commands to help monitor memory usage \u2014 and two of the most underrated ones are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>free -m<\/code><\/li>\n\n\n\n<li><code>watch -n 1 free -m<\/code><\/li>\n<\/ul>\n\n\n\n<p>Together, they give you a <strong>real-time, clear view of your memory status<\/strong>, right from the terminal.<\/p>\n\n\n\n<p>Let\u2019s dive into what these commands do and how you can use them like a pro.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0d What is <code>free -m<\/code>?<\/h2>\n\n\n\n<p>The <code>free<\/code> command shows <strong>how much memory and swap space<\/strong> is being used, free, cached, and available on your system.<\/p>\n\n\n\n<p>The <code>-m<\/code> flag tells <code>free<\/code> to display the values in <strong>megabytes<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Basic Usage:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>free -m<\/code><\/pre>\n\n\n\n<p>Sample Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>              total        used        free      shared  buff\/cache   available\nMem:           7824        1836         612         130        5375        5583\nSwap:          2047           0        2047\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Breakdown of the Output<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Column<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><strong>total<\/strong><\/td><td>Total RAM or swap space<\/td><\/tr><tr><td><strong>used<\/strong><\/td><td>Memory currently in use<\/td><\/tr><tr><td><strong>free<\/strong><\/td><td>Memory that is completely unused<\/td><\/tr><tr><td><strong>shared<\/strong><\/td><td>Memory shared between processes<\/td><\/tr><tr><td><strong>buff\/cache<\/strong><\/td><td>Memory used by buffers and cache<\/td><\/tr><tr><td><strong>available<\/strong><\/td><td>Estimation of memory available for new processes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udca1 Pro Tip:<\/h3>\n\n\n\n<p>Don\u2019t panic if <code>used<\/code> looks high. Linux uses <strong>free memory for caching<\/strong> to speed things up. The <code>available<\/code> column gives a better picture of what&#8217;s really usable.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd01 What is <code>watch -n 1 free -m<\/code>?<\/h2>\n\n\n\n<p>This command runs <code>free -m<\/code> <strong>every second<\/strong>, updating the output in real-time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Command:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>watch -n 1 free -m\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">What It Does:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>watch<\/code> runs a command repeatedly.<\/li>\n\n\n\n<li><code>-n 1<\/code> means run it <strong>every 1 second<\/strong>.<\/li>\n\n\n\n<li>So you get a <strong>live dashboard<\/strong> of memory usage.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcbc When to Use These Commands?<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udc22 Your system is slowing down<\/li>\n\n\n\n<li>\ud83e\udde0 You&#8217;re debugging memory leaks<\/li>\n\n\n\n<li>\ud83d\udee0\ufe0f You want to monitor how apps consume memory<\/li>\n\n\n\n<li>\ud83d\udd01 You&#8217;re watching memory usage during load tests<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Common Use Cases<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u2705 Monitor a Laravel app under load:<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>ab -n 1000 -c 10 http:\/\/localhost\/api\/test\nwatch -n 1 free -m\n<\/code><\/pre>\n\n\n\n<p>Watch how your app consumes memory during performance tests.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u2705 Detect Swap Usage:<\/h3>\n\n\n\n<p>If <code>Swap used<\/code> starts increasing, your physical RAM is full, and the system is using disk (much slower).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>free -m | grep Swap\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u2705 Combine with Process Monitoring:<\/h3>\n\n\n\n<p>Run in two terminals:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Terminal 1:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">watch -n 1 free -m<\/pre>\n\n\n\n<p>Terminal 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>htop\n<\/code><\/pre>\n\n\n\n<p>You\u2019ll see which process is using the memory in real time.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udccc Bonus Tip: Get a One-Liner Summary<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>free -m | awk 'NR==2{printf \"Used: %sMB | Free: %sMB | Available: %sMB\\n\", $3,$4,$7}'\n<\/code><\/pre>\n\n\n\n<p>This outputs something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Used: 1856MB | Free: 612MB | Available: 5583MB\n<\/code><\/pre>\n\n\n\n<p>Perfect for scripts and logs.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Final Thoughts<\/h2>\n\n\n\n<p>Whether you&#8217;re a system admin or a developer managing servers, keeping an eye on memory is crucial. Tools like <code>free -m<\/code> and <code>watch -n 1 free -m<\/code> are simple, fast, and already built into every Linux distro \u2014 no setup required.<\/p>\n\n\n\n<p>The next time your system lags or you run a big process, use these commands to stay one step ahead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When your Linux system starts slowing down, the first suspect is usually memory. Is RAM maxing out? Is swap being used? Is some process eating up everything?&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2513,2520,2511,2516,2515,2519,2521,2518,2514,2517,2522,2512],"class_list":["post-3041","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-free-m-command","tag-free-command-explained","tag-linux-memory-monitoring","tag-linux-performance-monitoring","tag-linux-swap-memory","tag-linux-terminal-commands","tag-memory-leak-detection-linux","tag-monitor-memory-usage","tag-real-time-ram-monitoring","tag-system-admin-tools","tag-watch-command-example","tag-watch-command-linux"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=3041"}],"version-history":[{"count":2,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3041\/revisions"}],"predecessor-version":[{"id":3043,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3041\/revisions\/3043"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=3041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=3041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=3041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}