how to monitor the processe usage of memory on linux .. eactly want to know how much each process take from memory
use the "top" command to see this interactively, or type "ps aux" to get a complete list of all the processes. You can then grep on it to get exact statistics for a specific process, like: "ps aux | grep apache".
It is generally difficult to know exactly how much memory is being used by shared library applications on Linux - typically though, you'd want the RSS column in the output of "ps aux".
Here are some top-like utilities that might be useful.
It's really difficult, because Linux supports shared memory, meaning that a task shares some or much of its memory with other processes.
To make matters worse, it also supports virtual memory which means that processes can have things notionally mapped in memory which aren't actually in physical memory at the time.
A thread is really just a special case of a task where the memory map is shared entirely with another.
All we have is:
- Virtual memory size - as reported by "top" in "VIRT" - this is the amount of address space that the process has mapped. Some of it might be mapped into things which don't use up physical memory (such as having the same file mapped more than once), and much of it might be mapped in but not allocated.
- Resident set size - the amount of memory which a process has mapped which are resident, i.e. in physical ram - but of course many of them will be shared with other processes.
Neither of them is exactly what we imagine by "memory usage".
Note that non-resident pages are not necessarily swapped out into a swap area - they are more typically demand-loaded pages (e.g. from mmap, libraries and executables) which haven't been loaded yet (or were previously loaded then discarded).
I can't find it right now but I think that some information can be found under /proc/, under those dirs that are just named with numbers (the process pids).
So for a process with pid 7365, you can start looking at something like /proc/7365/status.