我如何找出适合由shell脚本解析的linux盒的总物理内存(RAM)? [英] How can I find out the total physical memory (RAM) of my linux box suitable to be parsed by a shell script?

查看:120
本文介绍了我如何找出适合由shell脚本解析的linux盒的总物理内存(RAM)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在键入一个shell脚本以找出某些RHEL linux盒中的总物理内存.

I'm typing a shell script to find out the total physical memory in some RHEL linux boxes.

首先,我要强调的是,我对内核识别的总物理内存感兴趣,而不仅仅是可用内存.因此,请避免回答建议阅读/proc/meminfo 或使用免费顶部 sar 的答案.命令-在所有这些情况下,它们的"总内存"值表示"可用内存".

First of all I want to stress that I'm interested in the total physical memory recognized by kernel, not just the available memory. Therefore, please, avoid answers suggesting to read /proc/meminfo or to use the free, top or sar commands -- In all these cases, their "total memory" values mean "available memory" ones.

首先想到的是读取启动内核消息:

The first thought was to read the boot kernel messages:

Memory: 61861540k/63438844k available (2577k kernel code, 1042516k reserved, 1305k data, 212k init)

但是在某些Linux操作系统中,由于在内核启动中使用了EMC2的PowerPath软件及其 flooding 启动消息,因此即使在中也无法使用该有用的启动内核消息. /var/log/dmesg 文件.

But in some linux boxes, due to the use of EMC2's PowerPath software and its flooding boot messages in the kernel startup, that useful boot kernel message is not available, not even in the /var/log/dmesg file.

第二个选项是 dmidecode 命令(由于某些较早的内核和体系结构的限制,我警告内核识别的RAM和实际的RAM可能不匹配).选项-memory 简化了脚本,但我意识到该命令的较早版本没有-memory 选项.

The second option was the dmidecode command (I'm warned against the possible mismatch of kernel recognized RAM and real RAM due to the limitations of some older kernels and architectures). The option --memory simplifies the script but I realized that older releases of that command has no --memory option.

我最后一次机会是 getconf 命令.它报告内存页面的大小,但不报告物理页面的总数- _PHYS_PAGES 系统变量似乎是可用的物理页面,而不是物理页面的总数.

My last chance was the getconf command. It reports the memory page size, but not the total number of physical pages -- the _PHYS_PAGES system variable seems to be the available physical pages, not the total physical pages.


# getconf -a | grep PAGES
PAGESIZE                           4096
_AVPHYS_PAGES                      1049978
_PHYS_PAGES                        15466409

我的问题:还有另一种方法来获取适合由Shell脚本解析的物理内存总量吗?

My question: Is there another way to get the total amount of physical memory, suitable to be parsed by a shell script?

推荐答案

如果您对物理RAM感兴趣,请使用命令dmidecode.它不仅为您提供很多信息,但是根据您的用例,您可能还想知道系统中的8G是来自2x4GB记忆棒还是4x2GB记忆棒.

If you're interested in the physical RAM, use the command dmidecode. It gives you a lot more information than just that, but depending on your use case, you might also want to know if the 8G in the system come from 2x4GB sticks or 4x2GB sticks.

这篇关于我如何找出适合由shell脚本解析的linux盒的总物理内存(RAM)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆