{"id":133,"date":"2024-01-07T15:49:56","date_gmt":"2024-01-07T15:49:56","guid":{"rendered":"https:\/\/buyandhost.in\/blog\/?p=133"},"modified":"2024-01-08T09:56:50","modified_gmt":"2024-01-08T09:56:50","slug":"commands-to-check-memory-usage-in-linux","status":"publish","type":"post","link":"https:\/\/buyandhost.in\/blog\/commands-to-check-memory-usage-in-linux\/","title":{"rendered":"6 memory usage commands in linux"},"content":{"rendered":"\n<p>Memory usage in <a href=\"https:\/\/buyandhost.in\/web-hosting\/linux-hosting.html\" data-type=\"link\" data-id=\"https:\/\/buyandhost.in\/web-hosting\/linux-hosting.html\">Linux <\/a>refers to the utilization of Random Access Memory (RAM) by the operating system, applications, and various processes running on the system. RAM is a volatile form of memory used by the system to store data that is actively being used or processed by the CPU.<\/p>\n\n\n\n<p>Understanding memory usage is important for system administrators and users to ensure efficient system performance. Monitoring memory usage helps in identifying potential issues like memory leaks, resource-intensive applications, or insufficient RAM causing performance degradation.<\/p>\n\n\n\n<p>Memory usage in Linux can be categorized into several parts:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Total Memory<\/strong>: The total physical RAM available in the system.<\/li>\n\n\n\n<li><strong>Used Memory<\/strong>: The amount of RAM currently in use by the operating system, kernel, and running processes.<\/li>\n\n\n\n<li><strong>Free Memory<\/strong>: The amount of RAM not currently in use and available for immediate use.<\/li>\n\n\n\n<li><strong>Buffers and Cache<\/strong>: The memory used for buffering I\/O operations and caching frequently accessed data. This memory is considered as &#8220;used&#8221; but can be quickly released for applications if needed.<\/li>\n\n\n\n<li><strong>Swap Space<\/strong>: Disk space used as virtual memory when the physical RAM is fully utilized. It acts as an extension to RAM but is significantly slower.<\/li>\n<\/ol>\n\n\n\n<p>To check memory usage in Linux, various commands such as <code>free<\/code>, <code>top<\/code>, <code>htop<\/code>, <code>vmstat<\/code>, and examining <code>\/proc\/meminfo<\/code> provide information about memory statistics, including total memory, used memory, free memory, and other details.<\/p>\n\n\n\n<p>Efficient management of memory involves optimizing processes, reducing memory leaks, monitoring system performance, and considering hardware upgrades if the system frequently runs out of memory, impacting performance. It&#8217;s crucial to have a balance between available memory, system performance, and the requirements of running applications.<\/p>\n\n\n\n<p>In Linux, there are several commands available to check memory usage. Here are some commonly used commands:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"600\" src=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/memory-usage-1.png\" alt=\"\" class=\"wp-image-158\" srcset=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/memory-usage-1.png 1000w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/memory-usage-1-300x180.png 300w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/memory-usage-1-768x461.png 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#free-memory-usage-command\">free memory usage command:<\/a><\/li><li><a href=\"#top-command\">top command: <\/a><\/li><li><a href=\"#htop-command\">htop command: <\/a><\/li><li><a href=\"#vmstat-command\">vmstat command: <\/a><\/li><li><a href=\"#cat-proc-meminfo-command\">cat \/proc\/meminfo command: <\/a><\/li><li><a href=\"#ps-command\">ps command: <\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"free-memory-usage-command\"><strong>free<\/strong> memory usage command:<\/h2>\n\n\n\n<p>The command used to display free memory usage in Linux is <code><strong>free<\/strong><\/code>. This command provides information about the total amount of physical and swap memory, used memory, free memory, shared memory, and memory used for buffers and caches.<\/p>\n\n\n\n<p>The <strong><code>free<\/code> <\/strong>command displays information about total, used, and free memory in the system, including both physical and swap memory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>free -h <\/code><\/code><\/pre>\n\n\n\n<p>The <code>-h<\/code> flag is used for human-readable output, displaying sizes in KB, MB, GB, etc.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"92\" src=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/1-1024x92.png\" alt=\"\" class=\"wp-image-140\" srcset=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/1-1024x92.png 1024w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/1-300x27.png 300w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/1-768x69.png 768w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/1.png 1441w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"top-command\"><strong>top command<\/strong>: <\/h2>\n\n\n\n<p>The <code>top<\/code> command in Linux is a powerful and widely used command-line utility that provides a real-time interactive view of system resource usage. It offers a dynamic display of system processes and their resource consumption, including CPU usage, memory usage, process IDs (PIDs), running time, and more.<\/p>\n\n\n\n<p>The <code><strong>top<\/strong><\/code> command provides a real-time, interactive view of system resources, including memory usage. When you run <code>top<\/code>, press <code>Shift<\/code> + <code>M<\/code> to sort processes by memory usage.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>top<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"587\" src=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/2-1024x587.png\" alt=\"\" class=\"wp-image-142\" srcset=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/2-1024x587.png 1024w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/2-300x172.png 300w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/2-768x440.png 768w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/2-1536x880.png 1536w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/2.png 1573w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htop-command\"><strong>htop command<\/strong>: <\/h2>\n\n\n\n<p>The <code>htop<\/code> command is an interactive and feature-rich alternative to the traditional <code>top<\/code> command in Linux. It provides an improved and more user-friendly interface for monitoring system resources, displaying real-time information about processes, CPU usage, memory usage, and other system metrics.<\/p>\n\n\n\n<p>Similar to <strong><code>top<\/code> <\/strong>but offers a more user-friendly and customizable interface. It also provides real-time information about system resources including memory usage.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>htop<\/code><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"vmstat-command\"><strong>vmstat command<\/strong>: <\/h2>\n\n\n\n<p>The <code><strong>vmstat<\/strong><\/code> command in Linux is a system monitoring tool that provides information about system-wide virtual memory statistics, including processes, memory, paging, block IO, traps, and CPU activity. The name &#8220;vmstat&#8221; stands for &#8220;virtual memory statistics&#8221;.<\/p>\n\n\n\n<p>The <code><strong>vmstat<\/strong><\/code> command reports information about processes, memory, paging, block IO, traps, and CPU activity. To display memory-related information, you can run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>vmstat -s<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"610\" src=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/3-1024x610.png\" alt=\"\" class=\"wp-image-143\" srcset=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/3-1024x610.png 1024w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/3-300x179.png 300w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/3-768x458.png 768w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/3.png 1364w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cat-proc-meminfo-command\"><strong>cat \/proc\/meminfo<\/strong> command: <\/h2>\n\n\n\n<p>The <code>cat <strong>\/proc\/meminfo<\/strong><\/code> command in Linux is used to display detailed information about system memory (RAM) usage and related statistics. It reads the contents of the<strong> <code>\/proc\/meminfo<\/code><\/strong> file, which is a virtual file that provides real-time information about various memory-related metrics.<\/p>\n\n\n\n<p>The <code><strong>\/proc\/meminfo<\/strong><\/code> file contains detailed information about memory usage, including total, free, and used memory, as well as buffers and cache<a href=\"http:\/\/buyandhost.com\" target=\"_blank\" rel=\"noopener\">.<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>cat \/proc\/meminfo<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"738\" src=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/4-1024x738.png\" alt=\"\" class=\"wp-image-145\" srcset=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/4-1024x738.png 1024w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/4-300x216.png 300w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/4-768x553.png 768w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/4.png 1213w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ps-command\"><strong>ps command<\/strong>: <\/h2>\n\n\n\n<p>The <strong><code>ps<\/code> <\/strong>command in Linux is used to display information about currently running processes on a system. It provides a snapshot of active processes, showing details such as process IDs (PIDs), CPU and memory usage, execution time, and more.<\/p>\n\n\n\n<p>The <strong><code>ps<\/code> <\/strong>command can be used to display information about processes. To see memory usage for all processes, use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>ps aux --sort=-%mem <\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"458\" src=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/5-1024x458.png\" alt=\"\" class=\"wp-image-148\" srcset=\"https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/5-1024x458.png 1024w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/5-300x134.png 300w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/5-768x344.png 768w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/5-1536x687.png 1536w, https:\/\/buyandhost.in\/blog\/wp-content\/uploads\/2024\/01\/5.png 1889w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This sorts processes by memory usage, showing the most memory-consuming processes at the top.<\/p>\n\n\n\n<p>These commands provide various levels of detail about memory usage on a Linux system. Depending on your needs and preferences, you can choose the appropriate command to monitor memory usage effectively.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Memory usage in Linux refers to the utilization of Random Access Memory (RAM) by the operating system, applications, and various processes running on the system. RAM is a volatile form of memory used by the system to store data that is actively being used or processed by the CPU. Understanding memory usage is important for [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":160,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[9],"class_list":["post-133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-memory-usage"],"_links":{"self":[{"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":17,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/posts\/133\/revisions\/166"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/media\/160"}],"wp:attachment":[{"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buyandhost.in\/blog\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}