Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2416360
  • 博文数量: 298
  • 博客积分: 7876
  • 博客等级: 准将
  • 技术积分: 5500
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-23 13:39
文章存档

2013年(2)

2012年(142)

2011年(154)

分类: Python/Ruby

2012-05-07 17:37:51


点击(此处)折叠或打开

  1. #! /bin/bash

  2. echo -e "PID\t\tSwap\t\tProc_Name"
  3.  
  4. # 拿出/proc目录下所有以数字为名的目录(进程名是数字才是进程)
  5. (for pid in `ls -l /proc | grep ^d | awk '{ print $8 }'| grep -v ^[^0-9]`
  6. do
  7.     if [ ! -e /proc/$pid ];then
  8.         continue
  9.     fi
  10.     PName=$(cat /proc/$pid/cmdline)
  11.     awk -v name=$PName -v pid=$pid '
  12.     {
  13.          if($1 ~ /^Swap/)
  14.          {
  15.          swap += $2
  16.          }
  17.     }
  18.     END{
  19.         if(swap != 0)
  20.              print pid"\t\t"swap" kb\t\t"name
  21.      }' /proc/$pid/smaps 2>/dev/null
  22.  done) | sort -rnk2
执行结果:

点击(此处)折叠或打开

  1. PID        Swap        Proc_Name
  2. 356        816 kb        udevd--daemon
  3. 355        788 kb        udevd--daemon
  4. 265        776 kb        udevd--daemon
  5. 507        664 kb        rsyslogd-c4
  6. 827        484 kb        /usr/sbin/cupsd-F
  7. 617        480 kb        NetworkManager
  8. 434        428 kb        /usr/sbin/sshd-D
  9. 829        424 kb        gdm-binary
  10. 671        420 kb        /usr/lib/policykit-1/polkitd
  11. 667        304 kb        /usr/sbin/modem-manager
  12. 700        272 kb        /sbin/wpa_supplicant-u-s
  13. 732        172 kb        acpid-c/etc/acpi/events-s/var/run/acpid.socket
  14. 705        168 kb        /sbin/dhclient-d-4-sf/usr/lib/NetworkManager/nm-dhcp-client.action-pf/var/run/dhclient-eth0.pid-lf/var/lib/dhcp/dhclient-352800b5-14dd-4450-b596-a407f9cebf0f-eth0.lease-cf/var/run/nm-dhclient-eth0.confeth0
  15. 252        164 kb        upstart-udev-bridge--daemon
  16. 526        136 kb        dbus-daemon--system--fork--activation=upstart
  17. 1        120 kb        /sbin/init
  18. 735        112 kb        atd
  19. 734        112 kb        cron
  20. 726        80 kb        /sbin/getty-838400tty2
  21. 715        80 kb        /sbin/getty-838400tty4
  22. 730        76 kb        /sbin/getty-838400tty6
  23. 727        76 kb        /sbin/getty-838400tty3
  24. 719        76 kb        /sbin/getty-838400tty5
  25. 837        64 kb        /usr/sbin/console-kit-daemon--no-daemon
  26. 599        64 kb        upstart-socket-bridge--daemon
  27. 1202        4 kb        /usr/bin/gnome-keyring-daemon--daemonize--login
  28. 1062        4 kb        /sbin/getty-838400tty1


阅读(2070) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~