Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

migrated from serverfault.com Dec 20 '13 at 17:04

This question came from our site for professional system and network administrators.

    
Use pmap if you want to get real numbers –  Eric DANNIELOU Dec 20 '13 at 10:12

3 Answers 3

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 "" }'
share|improve this answer

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|improve this answer
    
munin and cacti have the downside of having 5mins granularity. sar or other custom scripts can be configured to take measure every minute. –  Eric DANNIELOU Dec 20 '13 at 10:14

In general you could view /proc/[pid]/status file. It includes VmPeak and RSS values.

If you are interested in RSS memory you could do something like:

while true ;  do ( echo -n `date` ""   ; grep RSS /proc/[pid]/status ) | tee -a /tmp/historyofrss ; sleep 0.1 ; done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.