Table of contents
1.
Introduction
2.
Linux
3.
Feature of Linux
4.
The "Top" command
4.1.
Syntax
5.
The “free” command
5.1.
Syntax
6.
The "Htop" command
6.1.
Syntax
7.
The "vmstat" command
7.1.
Syntax
8.
The "/proc/meminfo" command
8.1.
Syntax
9.
GUI
10.
Frequently Asked Questions
10.1.
What types of memory are there in a Linux system?
10.2.
How does the "htop" command in Linux vary from the typical "top" command?
10.3.
What is the command used to see a shared process's memory usage?
10.4.
What does the "vmstat" command show?
10.5.
What is the contrast between physical memory (RAM) and space in Linux?
11.
Conclusion
Last Updated: Feb 5, 2025
Easy

How to Check Memory Usage in Linux

Author Vidhi Sareen
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Do you want to understand how much memory your Linux computer is operating on? Understanding and knowledge about memory usage is important to ensure your computer runs efficiently. 

How to check memory usage in Linux

This article will teach us about simple Linux commands used to check memory usage. We can keep track of the computer's resources using these simple commands.

Linux

Like Windows and macOS, Linux belongs to the operating system category. The most thrilling thing about Linux is its freedom of use and the power to alter it according to personal interests without any cost. As a versatile operating system, Linux effectively functions on many platforms. Some are computers, servers, smartphones, and home appliances.

Linux

Linux, an adaptable operating system, works on computers, servers, smartphones, and home appliances. It permits people to do different things like surfing the internet, playing games, and running large servers for their websites.

Many corporations prefer using Linux for their servers due to several features. One of the main advantages is its robust security, which protects its data efficiently. Also, Linux shows flexibility, allowing companies to customize it according to their requirements. Furthermore, a large user community actively supports and assists with this.

Feature of Linux

Feature of Linux

There are many Features of linux operating system, such as:

  • Linux is an open-source operating system inviting people worldwide to access and modify its source code, fostering collaboration and continuous improvement within the developer community.
     
  • Linux provides users with diverse options to alter their operating system according to their preferences, enabling adaptability according to needs and requirements.
     
  • As an open-source operating system, Linux permits anyone to freely study, change, and spread its source code without restrictions.
     
  • Strong security measures in Linux help to prevent viruses and provide users control over system permissions.
     
  • Users can customize it to create unique desktop settings and software combinations.

The "Top" command

The top command displays the programs presently running on your computer. It enables you to monitor your computer's use and implementation. It's like a task manager that system administrators use to check the server's workload. The name "top" stands for "table of processes," it operates on various Unix-like operating systems to display details about memory and CPU usage.

Syntax

top

It consists of many fields and columns of the top command like:
 

  • PID: stands for process ID. It will represent the task id used in a process.
     
  • RUSER: stands for Real User Name. It shows the name of the owner that is using it.
     
  • PR: It demonstrates the priority.
     
  • NI: It shows the task's nice value. If the value is negative, then higher priority, or if the value is positive, then low priority. 
     
  • TIME: It shows the CPU time.
     
  • %MEM: it represents the percentage of memory usage.
     
  • %CPU: it represents the percentage of CPU usage by the process.
     
  • S: It represents the status of the process.
     
  • SHR: It represents the shared memory of the process.
output
output

The “free” command

The Linux command "free" enables you to check the memory RAM on your system or inspect the memory statistics of the Linux operating system. The free command outputs information about memory and swap, expressed in kibibytes when you run it without options.

Syntax

free

It consists of many fields and columns of the free command like:
 

  • Total: It represents the total RAM of the system.
     
  • Used: It represents the current memory that is currently in use.
     
  • Free: It represents free memory.
     
  • Shared: It represents shared memory among processes.
     
  • Available: It represents the estimated amount of memory available.
     
  • Buff/cache: It represents the memory that the kernel is using.
output
output

The "Htop" command

In Linux, people use the top command to observe real-time processor activity on a server. As an alternative to top, the “htop” command provides a more user-friendly interface with color, mouse operation, and the capability to scroll through processes. The “top” command does not have numerous other user-friendly features available in Htop.

Syntax

htop

If your Linux does not accept the Linux commands, you must install “htop” on your device. To do so, write the following command to the terminal.

$ sudo apt install htop
output
output

It is divided into three sections:

  • The upper section presents an overview featuring graphical meters and textual total indicators.
     
  • The bottom part contains complete information on each process and offers suitable ways to perform specific actions on individual processes.
     
  • You can manipulate and customize the processes quickly and without the need to type specific commands using the shortcuts listed at the bottom of the screen.
output

Below the window, you will observe that there are different functions available to you so that you can optimize your data according to your needs. You can sort your data according to priorityPIDUSER, or NICE.

output
output

The "vmstat" command

The “vmstat” command (virtual memory statistics) is a built-in monitoring tool used in Linux. Users can use this command to gather information about memory, system processes, paging, interrupts, block I/O, disk, and CPU scheduling. Users can observe system activity in real time by selecting a sampling period.

Syntax

vmstat
output

Vmstat -s command represents a table consisting of various events and memory statistics.

output

Vmstat -d command represents disk statistics.

output

The "/proc/meminfo" command

This computer file shows how much memory is currently available and being used. It shows you how much memory the system is currently using, including the memory used by the kernel for buffers and shared tasks. The results may differ depending on the computer type and operating system it uses.

Syntax

cat/proc/meminfo
output

GUI

In the Linux environment, a graphical user interface (GUI) system monitor tool exists that visually presents the memory usage and system resource utilization with a visual representation.

Many users widely use the System Monitor as a graphical user interface (GUI) tool for monitoring memory usage. The System Monitor is on numerous Linux distributions with a desktop environment. To access the System Monitor, navigate to the terminal and search for 'System Monitor.'

output
output

Frequently Asked Questions

What types of memory are there in a Linux system?

Physical Memory (RAM) triggers data and processes, and Swap Space is an extension of RAM found on the hard drive.

How does the "htop" command in Linux vary from the typical "top" command?

The "htop" delivers an interactive, color-coded, and better user-friendly interface than the standard "top" command in Linux, delivering an improved understanding of monitoring methods and system resources.

What is the command used to see a shared process's memory usage?

In Linux, you can verify how much memory a typical program uses using the "pmap" command supplying its process ID (PID) with it.

What does the "vmstat" command show?

In Linux, the "vmstat" command shows virtual memory statistics. It delivers real-time insights into memory usage, swapping, CPU activity, monitoring system performance, and identifying memory-related issues.

What is the contrast between physical memory (RAM) and space in Linux?

The RAM is the primary memory operated by the CPU for active tasks. Swap space acts as an extension of RAM, storing less-used data temporarily.

Conclusion

This article teaches us different ways to check memory usage in Linux. There are various ways, such as using "top" as a command-line tool used to monitor system processes, "free" displaying the free and used memory, "htop" as an interactive process viewer for the command line, "vmstat" showing virtual memory statistics and "/proc/meminfo" is a file that delivers memory related information about the system. All commands have their features, which make them unique. We also discuss some special features of Linux that make it so unique.

Do check out the link to learn more about such topic
 

 

You can find more informative articles or blogs on our platform. You can also practice more coding problems and prepare for interview questions from well-known companies on your platform, Coding Ninjas Studio.

Live masterclass