Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Tracing memory usage in Linux
Next article icon

Tracing memory usage in Linux

Last Updated : 08 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Memory is a critical resource in computing because its usage affects the performance and stability of a system. It's necessary to trace the memory usage of the system in order to determine the program that consumes all CPU resources or the program that is responsible for slowing down the activities of the CPU. 

Tracing memory usage also becomes necessary to determine the load on the server. Parsing the usage data enables the servers to be able to balance the load and serve the user's request without slowing down the system. In Linux, there are several ways to trace memory usage, and we are going to discuss them.

Using the `free` command to check memory usage in Linux.

free Displays the amount of memory that is currently available and used by the system (both physical and swapped). free command gathers this data by parsing /proc/meminfo. By default, the amount of memory is displayed in kilobytes.

free
free
free

To display the memory usage in megabytes every 5 seconds, we use the following command. Watch command is used to execute a program periodically.

watch -n 5 free -m
watch -n 5 free -m
watch -n 5 free -m

Using the `vmstat` command to check memory usage in Linux.

vmstat vmstat command is used to display virtual memory statistics of the system. This command reports data about the memory, paging, disk, and CPU activities, etc. The first use of this command returns the data averages since the last reboot. Further users return the data based on sampling periods of long delays.

 vmstat
 vmstat
 vmstat

To view disk statics

vmstat -d
vmstat -d
vmstat -d

 Displays the amount of memory used and available.

vmstat -s
vmstat -s
vmstat -s

Using the `top` command to check memory usage in Linux.

top command displays all the currently running processes in the system. This command displays the list of processes and thread currently being handled by the kernel. The top command can also be used to monitor the total amount of memory usage. 

top
top

Thread-mode operation. Displays individual thread that are currently in the system. Without this command option, a summation of all thread in each process is displayed.

 top -H 
 top -H
 top -H 

Using the `/proc/meminfo ` location to check memory usage in Linux.

/proc/meminfo This file contains all the data about the memory usage. It provides the current memory usage details rather than old, stored values. 

cat /proc/meminfo
cat /proc/meminfo
cat /proc/meminfo

Using the `htop ` command to check memory usage in Linux.

htop is an interactive process viewer. This command is similar to top command except that it allows to scroll vertically and horizontally to allows users to view all processes running on the system, along with their full command line as well as viewing them as a process tree, selecting multiple processes and acting on them all at once.

To use htop we need to install it in our system.

sudo apt-get install htop

Now we can use the following command.

htop
htop
htop

Conclusion

In this article we are discussing different methods to trace memory usage in Linux as memory usage is an essential aspect of computing which is used to optimize the performance and stability of a system. We have discussed commands like free, vmstat, top, /proc/meminfo, and htop.  By using these commands, we can monitor memory usage and diagnose problems that may occur in a system. Overall, we can say monitoring memory usage in Linux system is important for efficient system management.


Next Article
Tracing memory usage in Linux

M

Mayank Kumar 12
Improve
Article Tags :
  • Operating Systems
  • Linux-Unix
  • linux-command

Similar Reads

    What is Linux Operating System
    The Linux Operating System is a type of operating system that is similar to Unix, and it is built upon the Linux Kernel. The Linux Kernel is like the brain of the operating system because it manages how the computer interacts with its hardware and resources. It makes sure everything works smoothly a
    13 min read
    What is Linux Virtual Machine
    Whether you’re a developer, student, or IT professional, Linux VMs act as your personal sandbox, letting you safely explore, innovate, and break things without consequences. With a Linux VM, you can spin up a fully functional Ubuntu desktop inside Windows, host a Debian server on your MacBook, or ev
    9 min read
    Architecture of linux operating system
    Linux is an open-source UNIX-based operating system. The main component of the Linux operating system is Linux kernel. It is developed to provide low-cost or free operating system service to personal system users, which includes an X-window system, Emacs editor, IP/TCP GUI, etc.Linux distributionA L
    7 min read
    What is Real-Time Linux?
    Real-Time Linux is a specialized operating system kernel designed to provide deterministic and predictable behavior for time-sensitive applications. Unlike traditional Linux distributions, where processes and tasks are scheduled with varying degrees of priority and time-sharing, real-time Linux ensu
    3 min read
    Smem Tool To Display Memory Usage More Accurate in Linux
    Multiple tools are available to monitor the memory usage on a Linux system. Memory management by monitoring memory usage is one of the important things to do on our Linux system, Smem is one of the memory usage monitoring tools available in Linux. Smem displays the memory usage of the processes on t
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences