How much memory does that process use?

It’s a question that crops up very often for any PC user (well, the ones who are a bit geeky): how much memory is that process really using?

There is a very nice console tool in the procps package that can answer that question. It’s called pmap and from what I understand it’s found its way to Linux from Solaris.

When used with the -d flag, pmap will give you an outline of the way memory is mapped by the process you indicated and it will finish with a grand total. Look for the “shared” figure, that’s what you want. Why that? See detailed explanations here.

And to make your life easier and more interesing, here’s a shell script you can use. It looks under /proc for all the currently running processes, gets their names, runs pmap, extracts the relevant figures and produces a nicely formatted and sorted list:

cd /proc && \
echo -e "MEM\tPID\tPROCESS" >&2 && \
for PID in $(ls -d [1-9]*); do
 [ "$PID" = "$$" ] && continue
 [ -f "${PID}/status" ] && {
  NAME=$(head -1 "${PID}/status"|awk '{print $2}')
  MEM=$(pmap -d "$PID"|tail -1|awk '{print $4}')
  echo -e "${MEM}\t${PID}\t${NAME}"
 }
done|sort -n