Linux process current mem

How to check memory usage per process in Linux

Table of Contents

Linux check memory usage per process. how to check which process is using more memory in Linux. Linux how much memory is a process using. Linux track process memory usage over time. linux check memory usage per process in mb. Linux check memory. linux show memory usage. linux see memory usage. linux memory usage info. linux process memory usage. how to check memory usage in linux.


There are several metrics available to check memory usage per process in Linux. I will begin with the two that are easiest to obtain

  • the virtual set size (vss)
  • the resident memory size (rss)

both of which are available in most implementations of the ps and top commands.

    Vss: called VSZ in the ps command and VIRT in top , is the total amount of memory mapped by a process. It is the sum of all the regions shown in /proc/

/map . This number is of limited interest, since only part of the virtual memory is committed to physical memory at any one time.

  • Rss: called RSS in ps and RES in top , is the sum of memory that is mapped to physical pages of memory. This gets closer to the actual memory budget of the process, but there is a problem, if you add up the Rss of all the processes, you will get an overestimate the memory in use because some pages will be shared.
  • Using top and ps to check memory usage per process (VSS and RSS)

    The ps command shows Vss (VSZ) and Rss (RSS) with the options, -Aly , and a custom format which includes vsz and rss , as shown here

    Likewise free and top also shows a summary of the free memory and memory usage per process:

    Using smem to check memory usage per process

    In 2009, Matt Mackall began looking at the problem of accounting for shared pages in process memory measurement and added two new metrics called the unique set size or Uss , and the proportional set size or Pss

    • Uss: This is the amount of memory that is committed to physical memory and is unique to a process; it is not shared with any other. It is the amount of memory that would be freed if the process were to terminate.
    • Pss: This splits the accounting of shared pages that are committed to physical memory between all the processes that have them mapped. For example, if an area of library code is 12 pages long and is shared by six processes, each will accumulate two pages in Pss . Thus, if you add the Pss numbers for all processes, you will get the actual amount of memory being used by those processes. In other words, Pss is the number we have been looking for.

    The information is available in /proc/

    /smaps , which contains additional information for each of the mappings shown in /proc/

    Читайте также:  Образы операционных систем mac os

    /maps . Here is one section from such a file which provides information about the mapping for the libc code segment:

    There is a tool named smem that collates the information from the smaps files and presents it in various ways, including as pie or bar charts. The project page for smem is https://www.selenic.com/smem.

    There are various filters which you can apply with smem as shown below with the latest available release (1.4) at the time of writing this article

    To check memory usage per process in total we can execute below command

    This will give you memory usage detail of every process active on your system.

    To get the memory usage of a single process we can grep the process from the list

    Here as you see we get similar results as above with /proc/31768/smaps and with smem tool. So the actual memory usage of amsHelper is 56.4 MB

    Lastly I hope the steps from the article to check memory usage per process on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

    Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud

    If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

    For any other feedbacks or questions you can either use the comments section or contact me form.

    Thank You for your support!!

    5 thoughts on “How to check memory usage per process in Linux”

    There’s definately a lot to know about this
    issue. I really like all of the points you’ve made.

    I am happy that I noticed this site, precisely the right information that I was looking for! .

    Thank you – excellent writeup!
    But I would add this, from the smem man page: The USS and PSS only include physical memory usage. They do not include memory that has been swapped out to disk”
    I’d also note that it would be faster and easier to choose the process via the -P option:
    smem -k -P amsHelper

    Thank you for sharing this additional information.

    Cool! Thanks for the full ps flags to list the many kinds of memory options, as well as the tip about looking at the /proc/PID/smaps file for more information. I was trying to figure out how much memory one of my processes was consuming, but, alas, my Linux distro (running on an embedded system) has no way to install either smem or the other popular pmap tool. I’ve been just using good, old top for that, but your article gave me a vast array of many more suggestions! Thanks so much for that 🙂

    Источник

    5 commands to check memory usage on Linux

    Memory Usage

    On linux, there are commands for almost everything, because the gui might not be always available. When working on servers only shell access is available and everything has to be done from these commands. So today we shall be checking the commands that can be used to check memory usage on a linux system. Memory include RAM and swap.

    It is often important to check memory usage and memory used per process on servers so that resources do not fall short and users are able to access the server. For example a website. If you are running a webserver, then the server must have enough memory to serve the visitors to the site. If not, the site would become very slow or even go down when there is a traffic spike, simply because memory would fall short. Its just like what happens on your desktop PC.

    1. free command

    The free command is the most simple and easy to use command to check memory usage on linux. Here is a quick example

    The m option displays all data in MBs. The total os 7976 MB is the total amount of RAM installed on the system, that is 8GB. The used column shows the amount of RAM that has been used by linux, in this case around 6.4 GB. The output is pretty self explanatory. The catch over here is the cached and buffers column. The second line tells that 4.6 GB is free. This is the free memory in first line added with the buffers and cached amount of memory.

    Читайте также:  Avast windows offline installer

    Linux has the habit of caching lots of things for faster performance, so that memory can be freed and used if needed.
    The last line is the swap memory, which in this case is lying entirely free.

    2. /proc/meminfo

    The next way to check memory usage is to read the /proc/meminfo file. Know that the /proc file system does not contain real files. They are rather virtual files that contain dynamic information about the kernel and the system.

    Check the values of MemTotal, MemFree, Buffers, Cached, SwapTotal, SwapFree.
    They indicate same values of memory usage as the free command.

    3. vmstat

    The vmstat command with the s option, lays out the memory usage statistics much like the proc command. Here is an example

    The top few lines indicate total memory, free memory etc and so on.

    4. top command

    The top command is generally used to check memory and cpu usage per process. However it also reports total memory usage and can be used to monitor the total RAM usage. The header on output has the required information. Here is a sample output

    Check the KiB Mem and KiB Swap lines on the header. They indicate total, used and free amounts of the memory. The buffer and cache information is present here too, like the free command.

    5. htop

    Similar to the top command, the htop command also shows memory usage along with various other details.

    The header on top shows cpu usage along with RAM and swap usage with the corresponding figures.

    RAM Information

    To find out hardware information about the installed RAM, use the demidecode command. It reports lots of information about the installed RAM memory.

    Provided information includes the size (2048MB), type (DDR2) , speed(667 Mhz) etc.

    Summary

    All the above mentioned commands work from the terminal and do not have a gui. When working on a desktop with a gui, it is much easier to use a GUI tool with graphical output. The most common tools are gnome-system-monitor on gnome and
    ksysguard on KDE. Both provide resource usage information about cpu, ram, swap and network bandwidth in a graphical and easy to understand visual output.

    A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

    66 thoughts on “ 5 commands to check memory usage on Linux ”

    You have explained the topic very well. Thanks for sharing a nice article.

    Thanks for these commands. It saved a lots of time.

    How about explaining what we are looking for? Most people would know these commands. Waste of time.

    Please correct the typo in “RAM Information” section. The command for viewing hardware info about RAM is “dmidecode” and not “demidecode”.
    And it also requires root privileges.

    Источник

    Showing memory usage in Linux by process and user

    There are several commands for checking up on memory usage in a Linux system, and here are some of the better ones.

    There are a lot of tools for looking at memory usage on Linux systems. Some are commonly used commands like free and ps while others are tools like top that allow you to display system performance stats in various ways. In this post, we’ll look at some commands that can be most helpful in identifying the users and processes that are using the most memory.

    Here are some that address memory usage by process.

    Using top

    One of the best commands for looking at memory usage is top. One extremely easy way to see what processes are using the most memory is to start top and then press shift+m to switch the order of the processes shown to rank them by the percentage of memory each is using. Once you’ve entered shift+m, your top output should reorder the task entries to look something like this:

    Notice the %MEM ranking. The list will be limited by your window size, but the most significant processes with respect to memory usage will show up at the top of the process list.

    Using ps

    The ps command includes a column that displays memory usage for each process. To get the most useful display for viewing the top memory users, however, you can pass the ps output from this command to the sort command. Here’s an example that provides a very useful display:

    In the example above (truncated for this post), sort is being used with the -r (reverse), the -n (numeric) and the -k (key) options which are telling the command to sort the output in reverse numeric order based on the fourth column (memory usage) in the output from ps. If we first display the heading for the ps output, this is a little easier to see.

    If you like this command, you can set it up as an alias with a command like the one below. Don’t forget to add it to your

    /.bashrc file if you want to make it permanent.

    Here are some commands that reveal memory usage by user.

    Using top

    Examining memory usage by user is somewhat more complicated because you have to find a way to group all of a user’s processes into a single memory-usage total.

    If you want to home in on a single user, top can be used much in the same way that it was used above. Just add a username with the -U option as shown below and press the shift+m keys to order by memory usage:

    Using ps

    You can also use a ps command to rank an individual user’s processes by memory usage. In this example, we do this by selecting a single user’s processes with a grep command:

    Using ps along with other commands

    What gets complicated is when you want to compare users’ memory usages with each other. In that case, creating a by-user total and ranking them is a good technique, but it requires a little more work and uses a number of commands. In the script below, we get a list of users with the ps aux | grep -v COMMAND | awk ‘‘ | sort -u command. This includes system users like syslog. We then collect stats for each user and total the memory usage stat for each task with awk. As a last step, we display each user’s memory usage sum in numerical (largest first) order.

    Output from this script might look like this:

    There are a lot of ways to report on memory usage on Linux. Focusing on which processes and users are consuming the most memory can benefit from a few carefully crafted tools and commands.

    Sandra Henry-Stocker has been administering Unix systems for more than 30 years. She describes herself as «USL» (Unix as a second language) but remembers enough English to write books and buy groceries. She lives in the mountains in Virginia where, when not working with or writing about Unix, she’s chasing the bears away from her bird feeders.

    Источник

    Читайте также:  Windows определить доменное имя по ip
    Оцените статью