Memory usage by process


The Solaris pmap command will provide the total memory usage of each process.

The following shell script prints the memory usage of each process, sorted by ascending memory usage.
#!/bin/sh
/usr/bin/printf "%-6s %-9s %s\n" "PID" "Total" "Command"
/usr/bin/printf "%-6s %-9s %s\n" "---" "-----" "-------"
for PID in `/usr/bin/ps -e | /usr/bin/awk '$1 ~ /[0-9]+/ { print $1 }'`
do
CMD=`/usr/bin/ps -o comm -p $PID | /usr/bin/tail -1`
# Avoid "pmap: cannot examine 0: system process"-type errors
# by redirecting STDERR to /dev/null
TOTAL=`/usr/bin/pmap $PID 2>/dev/null | /usr/bin/tail -1 | \
/usr/bin/awk '{ print $2 }'`
[ -n "$TOTAL" ] && /usr/bin/printf "%-6s %-9s %s\n" "$PID" "$TOTAL" "$CMD"
done | /usr/bin/sort -n -k2

Example output:

PID Total Command
--- ----- -------
10214 1552K tee
10216 1552K tee
10431 1552K tee
10433 1552K tee
10430 1648K /bin/sh
10213 1728K /bin/sh
10436 1776K /bin/sh
10432 1792K /bin/sh
10215 1816K /bin/sh
1526 3912K /bin/sh
22547 3912K /bin/sh
22551 3912K /bin/sh
12384 4016K /bin/sh
1370 4032K /bin/sh
22462 4216K -csh
16458 4280K -csh
175 4920K vi
22468 5680K bash
16500 5744K bash
22460 9512K /usr/lib/ssh/sshd
22550 10872K /usr/bin/sort
10292 180360K /oracle/jrrt-3.1.2-1.6.0/bin/sparcv9/java
1532 750400K /oracle/jrrt-3.1.2-1.6.0/bin/sparcv9/java
1392 1056824K /oracle/jrrt-3.1.2-1.6.0/bin/sparcv9/java
12406 1160120K /oracle/jrrt-3.1.2-1.6.0/bin/sparcv9/java
10498 1233680K /oracle/jrrt-3.1.2-1.6.0/bin/sparcv9/java

Source: http://www.brandonhutchinson.com/Memory_usage_by_process.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: