#!/bin/sh
#
# collects info about the incore resident pages for all processes
# depends on valid info from /proc/#/statm and /proc/#/status
#

total_resident=0;
total_shared=0

#
# show some info about the process memory state
#
vmstatus() {
    #
    # from 'man proc'
    #
    read tmp name </proc/$1/status
    read size resident share trs drs lrs dt < /proc/$1/statm


    program_resident=$(($resident - $share))
    total_shared=$(($total_shared + $share))
    total_resident=$(($total_resident + $program_resident))

    echo -e "$program_resident\t$resident\t$share\t$trs\t$drs\t$lrs\t$dt\t$1\t$name"
}

cwd=`pwd`
echo -e "progres\ttotres\tshared\ttext\tdata\tlib\tdirty\tpid\tname\n";

cd /proc/
for pid  in [0-9]*  ; do
    vmstatus $pid;
done

echo "total shared $total_shared";
echo "total resident $total_resident";
cd $cwd
