Possible Duplicate:
Linux: How to measure actual memory usage of an application or process?
Why I use 'top' in Linux to show my memory of one process,I get that the storage of the process do only increase and do not decrease except I close the all process.I don't know why,though I use 'free' only behind 'malloc'. How can I get the correct actual REAL-TIME storage of my process? thanks all.
You can check memory of a process or a set of processes in human readable format (in KB or kilobytes) with pmap command. All you need is the PID of the processes you want to check memory usage of. As you can see, the total memory used by the process 917 is 516104 KB or kilobytes.
The top Command. Usually, we can use the Linux built-in top command. This command displays a real-time view of a running system in the command prompt. If we want to have an idea of a single process, we can use the -p parameter.
find the pid, if its running as the same user, use "ps aux", otherwise use "ps ax", then execute this:
cat /proc/<PID>/status
this should be all u want to know.
The short answer is that on a modern operating system this is very difficult.
Memory that is free()ed is not actually returned to the OS until the process terminates, so many cycles of allocating and freeing progressively bigger chunks of memory will cause the process to grow. (via)
This question has been already answered in more detail on another SO thread. You might find your answer there.
Depending upon the size of your allocations, your memory may or may not be returned to the OS. If you're allocating large things (see MMAP_THRESHOLD
in malloc(3)
), things that take many pages of memory, glibc will use mmap(2)
's MAP_ANONYMOUS
flag for the allocation; when you free(3)
this object, glibc can return the page to the OS, and your memory usage will go down.
You can tune MMAP_THRESHOLD
down using mallopt(3)
if you wish.
If you have many smaller allocations, your memory may be fragmented enough that free(3)
cannot actually free up an entire page that could be returned to the OS. You might have relatively little in use on a given page, but the entire page is still allocated against your process, and it replaces an entire page's worth of data from other processes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With