标题:
linux下查看进程使用swap情况及某一进程占用的内存
[打印本页]
作者:
linda
时间:
2022-4-13 17:14
标题:
linux下查看进程使用swap情况及某一进程占用的内存
#!/bin/bash
# Get current swap usage for all running processes
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
#echo "swap=$SWAP"
SUM=`expr $SUM + $SWAP`
#echo "sum=$SUM"
done
echo "PID=$PID - Swap used: $SUM - ($PROGNAME )"
OVERALL=`expr $OVERALL + $SUM`
SUM=0
done
echo "Overall swap used: $OVERALL"
---------
。。。
PID=12725 - Swap used: 272 - (apache2 )
PID=12726 - Swap used: 272 - (apache2 )
PID=12727 - Swap used: 272 - (apache2 )
PID=12730 - Swap used: 272 - (apache2 )
PID=12731 - Swap used: 272 - (apache2 )
PID=12732 - Swap used: 272 - (apache2 )
PID=12881 - Swap used: 272 - (apache2 )
PID=12882 - Swap used: 272 - (apache2 )
PID=12883 - Swap used: 272 - (apache2 )
PID=12884 - Swap used: 272 - (apache2 )
PID=21322 - Swap used: 0 - (dnsfilterd )
PID=21411 - Swap used: 0 - (named )
PID=21448 - Swap used: 0 - (webproxyd )
PID=21457 - Swap used: 0 - (webproxyd )
PID=21460 - Swap used: 0 - (basic_ncsa_auth )
PID=34438 - Swap used: 0 - (kworker/u2:1 )
PID=50520 - Swap used: 0 - (kworker/0:3-ata_sff )
PID=51024 - Swap used: 0 - (kworker/0:1-ata_sff )
PID=51515 - Swap used: 0 - (kworker/0:0-events )
PID=51519 - Swap used: 0 - (sh )
PID=51520 - Swap used: 0 - ( )
PID=51521 - Swap used: 0 - ( )
PID=51522 - Swap used: 0 - ( )
Overall swap used: 3924
原文:
https://zhidao.baidu.com/question/1887789951906747148.html
==========
查看内存占用前10位的进程:
ps auxwh 2>/dev/null | sort -rn -k4 | head -10
=========
查看某一进程占用的内存:
# ps -ylC apache2 | awk '{x += $8;y += 1} END {print "Apache Memory Usage (MB): "x/1024; print "Average Process Size (MB): "x/((y-1)*1024)}'
Apache Memory Usage (MB): 49.9258
Average Process Size (MB): 16.6419
参考:
https://serverfault.com/questions/951547/reduce-number-of-apache-processes
[
本帖最后由 linda 于 2022-4-13 18:52 编辑
]
欢迎光临 中神通公司技术论坛 (http://trustcomputing.com.cn/bbs/)
Powered by Discuz! 6.0.0