This question is covered here in great detail.
How do you measure the memory usage of an application or process in Linux?
From the blog article of Understanding memory usage on Linux, ps
is not an accurate tool to use for this intent.
Why
ps
is "wrong"Depending on how you look at it,
ps
is not reporting the real memory usage of processes. What it is really doing is showing how much real memory each process would take up if it were the only process running. Of course, a typical Linux machine has several dozen processes running at any given time, which means that the VSZ and RSS numbers reported byps
are almost definitely wrong.
I'm using
htop
; it's a very good console program similar to Windows Task Manager.There is no easy way to calculate this. But some people have tried to get some good answers:
This is an excellent summary of the tools and problems: archive.org link
I'll quote it, so that more devs will actually read it.
Get valgrind. give it your program to run, and it'll tell you plenty about its memory usage.
This would apply only for the case of a program that runs for some time and stops. I don't know if valgrind can get its hands on an already-running process or shouldn't-stop processes such as daemons.
Based on answer to a related question.
You may use SNMP to get the memory and cpu usage of a process in a particular device in network :)
Requirements:
Notes:
HOST-RESOURCES-MIB::hrSWRunPerfCPU is the number of centi-seconds of the total system's CPU resources consumed by this process. Note that on a multi-processor system, this value may increment by more than one centi-second in one centi-second of real (wall clock) time.
HOST-RESOURCES-MIB::hrSWRunPerfMem is the total amount of real system memory allocated to this process.
**
Process monitoring script:
**