linux统计全部进程内存使用情况
#!/bin/bash
echo "pid mem"
for j in `pgrep -P 1`
do
a=0
c=0
pgrep -P $j &> /dev/null
if [ $? -ne 0 ];then
b=`ps -eo pid,rss|egrep -w "^( $j| $j|$j)"|grep -v grep|awk '{print $2}'`
a=$[$a+$b+$c]
else
for i in `pgrep -P $j`
do
b=`ps -eo pid,rss|egrep -w "^( $i| $i|$i)"|grep -v grep|awk '{print $2}'`
c=`ps -eo pid,rss|egrep -w "^( $j| $j|$j)"|grep -v grep|awk '{print $2}'`
a=$[$a+$b+$c]
done
fi
echo $j $a >> 1.txt
done