首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

linux 系统查看物理内存使用率的命令,以百分比形式输出?

发布网友

我来回答

5个回答

热心网友

想监视系统内存?好像是没法直接得到现成的百分比的,自己取值计算一下吧

totalmem=`free -m | grep 'Mem' | awk '{print $3}'`

usedmem=`free -m | grep 'Mem' | awk '{print $2}'`

usage=$(bc<<EOF 

scale=4

($freemem/$totalmem)*100

EOF)

freeusage=`echo $free | awk -F. '{print $1}'`

echo "Free Memory Usage = $freeusage%"

以前Solaris里的改了改

只是个片段,需要什么判断之类自己填充到脚本里 一点点加吧 呵呵 希望对你有帮助

单要使用率的话二楼的更简练~~ 呵呵

free -m | sed -n '2p' | awk '{print "used mem is "$3"M,total mem is "$2"M,used percent is "$3/$2*100"%"}'

热心网友

用free命令,没有百分比,有KB,MB,GB,如下!
usage: free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit

热心网友

不用那么麻烦,这样就可以(centos7)
top -n 5 |sed -n '4p' |awk -F " " '{print $8/$4*100"%"}'
used除以total的结果。

热心网友

free -m | sed -n '2p' | awk '{print "used mem is "$3"M,total mem is “$2"M,used percent is "$3/$2"%"}'

热心网友

直接用top命令就行

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com