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
posted @ 2021-05-07 14:50  培天王  阅读(258)  评论(0编辑  收藏  举报