Ubuntu – How to find the amount of memory consumed by a process

linuxmemoryUbuntuvirtual-memory

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?

Best Answer

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 "" }'
Related Question