#!/bin/ksh
#
# This little tool checks the memory usage off all processes and creates a
# sorted output. It uses the 'pmap' and the 'ps' commands because their details
# for resident memory differs. I track this problem furthermore.
# The script runs until 1 minute because of the sort, so be patient :-))
# Written by A. Fischer, 11.05.06

echo "			pmap -x			ps -e -o 	"
echo "-     -  Kbytes Resident Shared Private  ==> PID  VSZ  RSS  PMEM  ARGS"
for i in $(ps -e|awk '/[:digit:]/ { print $1 }');do
	MEMUSE=$(pmap -x $i 2> /dev/null|sed -e 's/^  *//g'|egrep "^total")
	if [ -z $MEMUSE ];then
		continue
	else
		PROC=`ps -e -o pid,vsz,rss,pmem,args|grep "^ *$i "|grep -v grep`
		echo "$MEMUSE ==> $PROC"
	fi
done|sort -rn -k3,3

