Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

6 Answers 6

up vote 8 down vote accepted

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.

share|improve this answer
    
pmap is really the best answer.. you will get the most details from it. –  Mike Apr 29 '11 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 '11 at 0:10
add comment

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.

share|improve this answer
    
There are many forks of mac htop floating around. I added CPU temperature to mine. –  Barry Oct 7 '12 at 17:54
add comment

type "top" into your command line

share|improve this answer
1  
Also, shift + M inside top to order by processes with the highest memory usage. –  Matt Beckman Apr 29 '11 at 19:28
add comment
ps aux # look at mem% and rss and vsz
share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
2  
It also takes about 10x the resources to run, for very minimal benefit. –  EEAA Apr 29 '11 at 19:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.