查看swap占用情况
查看swap被占用的情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #!/bin/bash # Get current swap usage for all running processes # Erik Ljungstrom 27/05/2011 # http://northernmost.org/blog/find-out-what-is-using-your-swap/ SUM = 0 OVERALL = 0 for DIR in `find / proc / - maxdepth 1 - type d | egrep "^/proc/[0-9]" ` ; do PID = `echo $ DIR | cut - d / - f 3 ` PROGNAME = `ps - p $PID - o comm - - no - headers` for SWAP in `grep Swap $ DIR / smaps 2 > / dev / null| awk '{ print $2 }' ` do let SUM = $ SUM + $SWAP done echo "PID=$PID - Swap used: $SUM - ($PROGNAME )" let OVERALL = $OVERALL + $ SUM SUM = 0 done echo "Overall swap used: $OVERALL" |
使用:
1 2 3 4 5 6 7 8 9 10 11 12 | [root@standby ~] # ./swap.sh |sort -nr -k 5 |head -10 PID = 13899 - Swap used: 2071424 - ([ET_NET 0 ] ) PID = 4124 - Swap used: 741224 - (nginx ) PID = 19965 - Swap used: 741212 - (nginx ) PID = 19960 - Swap used: 741212 - (nginx ) PID = 19969 - Swap used: 741172 - (nginx ) PID = 19968 - Swap used: 741172 - (nginx ) PID = 19967 - Swap used: 741172 - (nginx ) PID = 19966 - Swap used: 741172 - (nginx ) PID = 19964 - Swap used: 741172 - (nginx ) PID = 19962 - Swap used: 741172 - (nginx ) [root@standby ~] # |
查看指定进程的swap占用情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #!/bin/bash # Get current swap usage for input process. # 71standby@gmail.com function Usage() { echo - e "Usage: / bin / sh $ 0 keyword \n \ keyword: which to match the process that you wanna statistics.\n \ Example: 'traffic' will match the traffic_cop,traffic_manager,traffic_server and so on." exit 2 } function Statistics() { SUM = 0 OVERALL = 0 for PID in `ps - ef |grep $ 1 |grep - v grep |grep - v $ 0 |awk '{print $2}' `; do PROGNAME = `ps - p $PID - o comm - - no - headers` DIR = / proc / $PID / smaps for SWAP in `grep Swap $ DIR 2 > / dev / null| awk '{ print $2 }' `; do let SUM = $ SUM + $SWAP done echo "PID=$PID - Swap used: $SUM - ($PROGNAME)" let OVERALL = $OVERALL + $ SUM SUM = 0 done echo "$1 swap used: $OVERALL" } if [ $ # -ne 1 ]; then Usage else Statistics $ 1 fi |
使用:
1 2 3 4 5 6 | [root@standby ~] # ./swap_show.sh traffic PID = 48575 - Swap used: 764 - (traffic_cop) PID = 48577 - Swap used: 12948 - (traffic_manager) PID = 48588 - Swap used: 3823100 - ([ET_NET 0 ]) traffic swap used: 3836812 [root@standby ~] # |
作者:Standby — 一生热爱名山大川、草原沙漠,还有我们小郭宝贝!
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/standby/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步