LoginSignup
2
2

More than 5 years have passed since last update.

さくっとプロセスの Rss と Shared_Clean + Shared_Dirty のサイズを計算

Posted at
echo $(( $(cat /proc/6941/smaps | grep ^Rss | awk '{print $2 "+"}') 0 ))
echo $(( $(cat /proc/6941/smaps | grep ^Shared | awk '{print $2 "+"}') 0 ))

ついでに、まとめて Rss と Shared_Clean + Shared_Dirty とその比率を出力。

for pid in $(pgrep http); do
    rss=$(( $(cat "/proc/$pid/smaps" | grep ^Rss | awk '{print $2 "+"}') 0 ))
    shared=$(( $(cat "/proc/$pid/smaps" | grep ^Shared | awk '{print $2 "+"}') 0 ))
    name=$(cat "/proc/$pid/cmdline" | tr '\0' ' ')
    printf "%d\t%d\t%d\t%d%%\t%s\n" "$pid" "$rss" "$shared" "$(($shared*100/$rss))" "$name"
done

次のように結果が表示される。

6932    455596  444156  97%     /usr/sbin/httpd 
6933    455964  444164  97%     /usr/sbin/httpd 
6935    455308  444228  97%     /usr/sbin/httpd 
6939    455812  444184  97%     /usr/sbin/httpd 
6940    455968  444176  97%     /usr/sbin/httpd 
6941    455968  444228  97%     /usr/sbin/httpd 
6942    455960  444192  97%     /usr/sbin/httpd 
6943    455756  444180  97%     /usr/sbin/httpd 
8092    455960  444184  97%     /usr/sbin/httpd 
13370   451436  445800  98%     /usr/sbin/httpd 
24533   455964  444292  97%     /usr/sbin/httpd 
2
2
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
2
2