How can I find the amount of memory consumed by a process?

10,780

Solution 1

It sounds like you really need some type of continuous monitoring tool to record statistics like memory usage over time.

I would suggest what you are doing now and repeatedly running the ps command to get size of memory used per process.

You would need a way to parse the output into a human-readable chart or table to show values over time.

Personally, I like this little command I had taken from someone on another forum to show memory usage in a human-readable way:

ps -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }'

Solution 2

The atop tool can be useful here. It can run as a daemon and store information about resource consumption of every process periodically. It offers you the possibility to scroll back through the results which allows you to find out what the maximum amount of memory used by the process is.

Other alternatives are tools like munin and cacti which can graph memory consumption per process (and many other things).

Share:
10,780

Related videos on Youtube

Admin
Author by

Admin

Updated on November 25, 2022

Comments

  • Admin
    Admin over 1 year

    How can I find the amount of main memory consumed by a process using ps aux?

    I have a process which runs for half an hour. Is it possible to find the maximum amount of main memory consumed by it using ps aux?

    I tried to run ps aux but it only gives me the amount of memory consumed at the time I ran it. I do not see how I can find the maximum amount of main memory consumed by the process. One option is to run ps again and again and to keep looking at the output. I do not find that option feasible enough. Is there any other way out in Linux?

    • Admin
      Admin over 10 years
      Use pmap if you want to get real numbers
  • Admin
    Admin over 10 years
    munin and cacti have the downside of having 5mins granularity. sar or other custom scripts can be configured to take measure every minute.