在CentOs6.4下,用root权限测试。
# cd ~ //进入home目录
# vim .bashrc //编辑文件,把下面代码放入地址
mem ()
{
top -n1 -b | head -n7 | sed '1,6d' && top -n1 -b | sed '1,7d' | grep --color=auto $1;
ps aux | grep --color=auto $1 | grep --color=auto -v grep | awk -F " " '{ sum += $6 } END { printf "Total Memory Usage: %.1f MB/n", sum/1024 }'
}
# source .bashrc //使命令生效
测试
~查看PHP或者nginx的占用内存~
[[email protected] ~]# mem php
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
24984 root 20 0 336m 8212 1640 S 0.0 0.8 0:00.03 php-fpm
24985 www 20 0 336m 7776 1192 S 0.0 0.8 0:00.01 php-fpm
24986 www 20 0 336m 7776 1192 S 0.0 0.8 0:00.01 php-fpm
24987 www 20 0 336m 7776 1192 S 0.0 0.8 0:00.05 php-fpm
24988 www 20 0 336m 7776 1192 S 0.0 0.8 0:00.03 php-fpm
24989 www 20 0 336m 7784 1196 S 0.0 0.8 0:00.00 php-fpm
24990 www 20 0 336m 7784 1196 S 0.0 0.8 0:00.01 php-fpm
24991 www 20 0 336m 78m 71m S 0.0 7.9 0:07.50 php-fpm
24992 www 20 0 336m 7784 1196 S 0.0 0.8 0:00.04 php-fpm
24993 www 20 0 336m 77m 70m S 0.0 7.8 0:09.19 php-fpm
24994 www 20 0 340m 84m 74m S 0.0 8.6 0:07.78 php-fpm
Total Memory Usage: 301.4 MB
[[email protected] ~]# mem nginx
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2824 root 20 0 40660 2684 488 S 0.0 0.3 0:00.01 nginx
2832 www 20 0 71380 27m 1124 S 0.0 2.8 0:00.99 nginx
2833 www 20 0 71380 22m 1036 S 0.0 2.3 0:00.46 nginx
2834 www 20 0 71380 29m 1180 S 0.0 3.0 0:02.92 nginx
2835 www 20 0 71380 29m 1120 S 0.0 3.0 0:11.48 nginx
Total Memory Usage: 111.2 MB
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/2286.html