17

How can I find out the total memory allocated for a particular process in Ubuntu?

Anjali
  • 179

3 Answers3

17

Try:

pidof bash | xargs ps -o rss,sz,vsz

To find the memory usage of your current bash shell (assuming you're using bash). Change 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>

From the man page:

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).

The 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.

garethTheRed
  • 33,957
5

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.

0

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 ps, pmap, top, htop etc....). Read proc(5) for more. In particular for process of pid 1234 you could use /proc/1234/status, /proc/1234/statm, /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 /proc/self/status etc...

See also LinuxAteMyRam.