Obtaining memory usage through ps is pretty unreliable. If you have a newer kernel it should support /proc/pid#/smaps which gives you some detailed information on each processes memory usage. Below is a pretty dirty and quick script to loop through each process that is open and grab the Size, Rss, Pss and Shared Clean/Dirty usage. Hopefully it can be useful in some kind of way.
#!/bin/bash
for pid in $(ps -ef | awk '{print $2}'); do
if [ -f /proc/$pid/smaps ]; then
echo "* Mem usage for PID $pid"
echo "-- Size:"
cat /proc/$pid/smaps | grep -m 1 -e ^Size: | awk '{print $2}'
echo "-- Rss:"
cat /proc/$pid/smaps | grep -m 1 -e ^Rss: | awk '{print $2}'
echo "-- Pss:"
cat /proc/$pid/smaps | grep -m 1 -e ^Pss: | awk '{print $2}'
echo "Shared Clean"
cat /proc/$pid/smaps | grep -m 1 -e '^Shared_Clean:' | awk '{print $2}'
echo "Shared Dirty"
cat /proc/$pid/smaps | grep -m 1 -e '^Shared Dirty:' | awk '{print $2}'
fi
done