Linux top memory usage processes

Find Top Running Processes by Highest Memory and CPU Usage in Linux

I remember once reading that efficient system administrators are lazy people. The reason is not that they’re not doing their job or wasting their time – it is mostly because they have automated a good deal of their routine tasks. Thus, they don’t have to babysit their servers and can use their time to learn new technologies and always stay at the top of their game.

Part of automating your tasks, is learning how to get a script do what you would have to do yourself otherwise. Continually adding commands to your own knowledge base is just as important.

For that reason, in this article we will share a trick to find out, which processes are consuming lots of Memory and CPU utilization in Linux.

Find Linux Processes By RAM and CPU Usage

That said, let’s dive in and get started.

Check Top Processes sorted by RAM or CPU Usage in Linux

The following command will show the list of top processes ordered by RAM and CPU use in descendant form (remove the pipeline and head if you want to see the full list):

Sample Output

Brief explanation of above options used in above command.

The -o (or –format) option of ps allows you to specify the output format. A favorite of mine is to show the processes’ PIDs (pid), PPIDs (pid), the name of the executable file associated with the process (cmd), and the RAM and CPU utilization ( %mem and %cpu , respectively).

Additionally, I use —sort to sort by either %mem or %cpu . By default, the output will be sorted in ascendant form, but personally I prefer to reverse that order by adding a minus sign in front of the sort criteria.

To add other fields to the output, or change the sort criteria, refer to the OUTPUT FORMAT CONTROL section in the man page of ps command.

Summary

Monitoring process is one of the numerous tasks of a Linux server system administrator, in this tip, we looked at how you list processes on your system and sort them according to RAM and CPU use in descendant form using the ps utility.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

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/

    /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 🙂

    Читайте также:  Как удалить временные файлы после обновления windows

    Источник

    How to see top processes sorted by actual memory usage?

    I have a server with 12G of memory. A fragment of top is shown below:

    The free -m shows the following:

    If I understand correctly, the system has only 362 MB of available memory. My question is: How can I find out which process is consuming most of the memory?

    Just as background info, the system is running 64bit OpenSuse 12 .

    12 Answers 12

    use quick tip using top command in linux/unix

    and then hit Shift + m (i.e. write a capital M ).

    Or alternatively: hit Shift + f , then choose the display to order by memory usage by hitting key n then press Enter . You will see active process ordered by memory usage

    First, repeat this mantra for a little while: «unused memory is wasted memory». The Linux kernel keeps around huge amounts of file metadata and files that were requested, until something that looks more important pushes that data out. It’s why you can run:

    and have the second find instance run at ridiculous speed.

    Linux only leaves a little bit of memory ‘free’ to handle spikes in memory usage without too much effort.

    Second, you want to find the processes that are eating all your memory; in top use the M command to sort by memory use. Feel free to ignore the VIRT column, that just tells you how much virtual memory has been allocated, not how much memory the process is using. RES reports how much memory is resident, or currently in ram (as opposed to swapped to disk or never actually allocated in the first place, despite being requested).

    But, since RES will count e.g. /lib/libc.so.6 memory once for nearly every process, it isn’t exactly an awesome measure of how much memory a process is using. The SHR column reports how much memory is shared with other processes, but there is no guarantee that another process is actually sharing — it could be sharable, just no one else wants to share.

    The smem tool is designed to help users better gage just how much memory should really be blamed on each individual process. It does some clever work to figure out what is really unique, what is shared, and proportionally tallies the shared memory to the processes sharing it. smem may help you understand where your memory is going better than top will, but top is an excellent first tool.

    Источник

    Find Top 15 Processes by Memory Usage with ‘top’ in Batch Mode

    Similarly to the previous tip about find out top processes by RAM and CPU usage, you can also use top command to view the same information. Perhaps there’s an extra advantage of this approach when compared to the previous one: the “header” of top provides extra information about the current status and usage of the system: the uptime, load average, and total number of processes, to name a few examples.

    Find Processes By Memory Usage with top

    To display the top 15 processes sorted by memory use in descending order, do:

    As opposed to the previous tip, here you have to use +%MEM (note the plus sign) to sort the output in descending order:

    List Top 15 Processes By Memory Usage

    From the command above, the option:

    1. -b : runs top in batch mode
    2. -o : used to specify fields for sorting processes
    3. head utility displays the first few lines of a file and
    4. the -n option is used to specify the number of lines to be displayed.

    Note that head utility, by default displays the first ten lines of a file, that is when you do not specify the number of lines to be displayed. Therefore, in the example above, we displayed the first 22 lines of top command output in batch mode.

    Redirect or Save ‘top’ Output to File in Linux

    Additionally, using top in batch mode allows you to redirect the output to a file for later inspection:

    As we have seen, the top utility offers us more dynamic information while listing processes on a Linux system, therefore, this approach has an extra advantage compared to using ps utility which we covered in tip one.

    Читайте также:  Manjaro linux для планшета

    But most importantly, you must always run top in batch mode to redirect its output to a file or another process. Additionally, if you have any tips regarding use of top, you can also share them with us via the feedback form below.

    If You Appreciate What We Do Here On TecMint, You Should Consider:

    TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

    If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

    We are thankful for your never ending support.

    Источник

    How to check memory usage per process in Linux

    You may have noticed that sometimes your system consumes too much of memory, which makes your application’s slow or unresponsive.

    In such a scenario, what do you think would be the best approach to identify the processes that are consuming more memory in a Linux machine?

    This can be easily identified using the top command and the ps command and we will explain how to use these two commands to identify which processes are eating all the resources on your system.

    I have used both the commands simultaneously and both gave me the same result in my scenario.

    I hope some of you have already tried to find this information using one of the below commands. If not, what other commands did you try?

    I would request you to share with us any other commands that you have tried in the comment section below to help other users.

    Check out the following article(hyperlink) if you want to find a list of processes that consume most of your CPU resources:

    In this guide, we’ll show you how to check which process is taking more memory in Linux.

    1) Find out top memory consuming process in Linux using ‘ps’ command

    The ‘ps’ command is used to report a snapshot of the current processes. The ‘ps’ command stands for process status.

    This is a standard Linux application that looks for information about running processes on a Linux system.

    It is used to list the currently running processes and their process ID’s (PID), process owner name, process priority (PR), and the absolute path of the running command, etc.

    The below ‘ps’ command check memory usage per process in Linux:

    Use the below ‘ps’ command format to include a specific information about such processes in the output:

    If you want to see only the command name instead of the absolute path of the command, use the following ‘ps’ command format:

    2) How to check memory usage per process in Linux using ‘top’ command

    The Linux ‘top’ command is the best and widely used command that everyone uses to monitor Linux system performance.

    It displays a real-time view of the system processes running on the interactive interface.

    You should run the top command in batch mode to find out top memory consuming processes in Linux.

    In addition, you need to understand the top command output correctly to fix the performance issue on the system.

    If you only want to see the command name instead of the absolute path of the command, use the below top command format:

    3) Bonus Tips: Checking memory usage in Linux by process using ‘ps_mem’ command

    The ps_mem utility is used to display the core memory used per program (not per process).

    This utility allows you to check how much memory is used per program.

    It calculates the amount of private and shared memory against a program and returns the total used memory in the most appropriate way.

    It uses the following logic to calculate RAM usage. Total RAM = sum (private RAM for program processes) + sum (shared RAM for program processes).

    The below ‘ps_mem’ command showing memory usage in Linux by process.

    Over to You

    In this tutorial, we have shown you how to use ‘top’ & ‘ps’ commands to identify the most memory consuming processes in Linux.

    If you found this article helpful, please do share with your friends and spread the knowledge. Please feel free to comment below if you have any queries/concerns. We will get back to you as soon as we can. Happy learning!

    Источник

    Оцените статью