8

how can I see the memory usage of a Linux process?

6 Answers 6

14

You might want to have a look at 'pmap', e.g.

pmap -d [PROCESS ID]

At the bottom you will see how much memory is shared and how much of it is private to the process. For example: Some applications look like they use an awful lot of memory, but in reality it is just a lot of shared libraries that are taken into the calculation.

2
  • pmap is really the best answer.. you will get the most details from it.
    – Mike
    Apr 29, 2011 at 20:27
  • pmap -d won't show you the resident set size, which I think is the most important single figure to know when evaluating memory usage. pmap -x will show this.
    – sciurus
    Apr 30, 2011 at 0:10
9

On Linux: top: press [i] to enable column sorting. [<] or [>] to move the sort columns. Note the not-so-secret color mode by pressing [z] [x] [y] [X] [Y] change sort highlighting/color style.

free, ps auv shows swap too, sar (sysstat/psacct) are great for trending. slabtop, vmstat for the kernel. In general, watch is quick and easy for monitoring arbitrary commands but wastes processes watch -n0.3 'ps auv | grep top' watch -n5 'lsof | grep top | grep -v grep | wc -l'. A quick, reusable script is often a better way to go.

To really dig in when compiling from source, tcmalloc from google perftools.

For ongoing trending, have a look at collectd and cacti.

On Mac:

htop vs. top

  • Resident Set Size: 1530 1770 (error <10)
  • open files: 8 9

Average of 10 samples taken sequently after an hour. If I'm missing something, which I prol am, let me know.

1
  • There are many forks of mac htop floating around. I added CPU temperature to mine.
    – user31170
    Oct 7, 2012 at 17:54
4

ps -o vsz,rss,%mem -p $PROCESS_ID

This will show the amount of memory the program has requested (virtual set size), how much is currently stored in RAM (resident set size), and what percentage that is of your total RAM.

For an explanation of the first two numbers that includes examples of analyzing real program behavior, read this atop case study analyzing memory leakage. If that's too much, at least read the "introduction to virtual memory" section.

Calculating the resident set size of a program is complicated by shared memory. Devin has a great explanation how shared memory can be accounted for using pmap to determine the marginal cost of starting another process.

3

type "top" into your command line

1
  • 1
    Also, shift + M inside top to order by processes with the highest memory usage. Apr 29, 2011 at 19:28
3
ps aux # look at mem% and rss and vsz
2

Try htop (http://htop.sourceforge.net/). IMHO is better (easyer than top)

1
  • 2
    It also takes about 10x the resources to run, for very minimal benefit.
    – EEAA
    Apr 29, 2011 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .