0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

httpd が使用する物理メモリの合計を得る.sh

Posted at

ps の httpd から pid をとりだして、 /proc/[pid]/smaps から
PRIVATE だけを足したもの

echo -e "PID\tRSS\tSHARED\tPRIVATE";
ps -ef | grep httpd | grep -v root | grep -v grep | while read line; do
        args=($line);

        echo -ne "${args[1]}\t"

        cat /proc/${args[1]}/smaps | awk '
                BEGIN{ rss=0; shared=0; private=0; }
                        /Rss/{rss += $2;}
                        /Shared/{shared += $2;}
                        /Private/{private += $2;}
                END{ printf("%.1f\t%.1f\t%.1f\n",
                        rss / 1024,
                        shared / 1024,
                        private / 1024)
        }';
done > /tmp/apache-mem.txt
sort -nk 4 /tmp/apache-mem.txt
echo -e "PID\tRSS\tSHARED\tPRIVATE";
cat /tmp/apache-mem.txt | awk 'BEGIN{i=0; sum=0;}{i+=1;sum+=$4}END{ print "Total: " sum " Mb " i " Processes"}'

以下にあるスクリプトがうまくうごかなかったので、すこし手直ししました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?