How can I find out the total memory allocated for a particular process in Ubuntu?
pidof bash | xargs ps -o rss,sz,vsz
To find the memory usage of your current
bash shell (assuming you're using
bash to whatever you're investigating. If you're after one specific process, simply use on it's own:
ps -o rss,sz,vsz <process id>
RSS: resident set size, the non-swapped physical memory that a task has used (in kiloBytes).
SZ: size in physical pages of the core image of the process. This includes text, data, and stack space.
VSZ: virtual memory size of the process in KiB (1024-byte units).
man page for
ps will list all the possible arguments to the
-o option (there are quite a few to choose from). Instead of
-o rss,sz you could use the BSD style
v option (no dash) which shows an alternative memory layout.
You can use
pmap which shows the memory map of a process:
pmap -p pid
For more information about it see the man page
man pmap or have a look at pmap(1): report memory map of process - Linux man page.
how to find out the total memory allocated for a particular process in ubuntu?
You don't define what is the memory allocated for a process, and actually that is a pretty complex question (what about shared memory mappings - see mmap(2) for details; what about POSIX shared memory - see shm_overview(7) for more; what about some pages in the page cache used for opened files; etc...)
You could use the
/proc/ file system (which BTW is used by
htop etc....). Read proc(5) for more. In particular for process of pid 1234 you could use
/proc/1234/maps etc... They are all textual pseudo-files (a bit like pipes) that you can see with
cat (or read sequentially inside some program). BTW, from inside a program you might use
/proc/self (which is a pseudo symlink), e.g. read sequentially
See also LinuxAteMyRam.