如何从 Windows 命令行检索可用 RAM?

发布于 2025-01-01 13:21:40 字数 96 浏览 0 评论 0原文

Windows 或第三方程序中是否有命令行实用程序可以检索计算机上的可用 RAM? (因为我不相信这可以在纯JAVA中完成,因为它是在虚拟机中运行,并且已经预设/分配了RAM)?

Is there a command line utility within Windows or third-party program that can retrieve available RAM on a machine? (Since I don't believe this can be done in pure JAVA, since it is run within a virtual machine, that has preset / allocated RAM)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

南汐寒笙箫 2025-01-08 13:21:40

systeminfo 是一个命令,将输出系统信息,包括可用内存

systeminfo is a command that will output system information, including available memory

ぺ禁宫浮华殁 2025-01-08 13:21:40
wmic OS get FreePhysicalMemory /Value
wmic OS get FreePhysicalMemory /Value
柒七 2025-01-08 13:21:40

使用wmiccomputersystem获取TotalPhysicalMemory。例如:

C:\>wmic computersystem get TotalPhysicalMemory
TotalPhysicalMemory
4294500352

Use wmic computersystem get TotalPhysicalMemory. E.g.:

C:\>wmic computersystem get TotalPhysicalMemory
TotalPhysicalMemory
4294500352
浴红衣 2025-01-08 13:21:40
wmic OS get TotalVisibleMemorySize /Value

请注意,不是其他地方建议的 TotalPhysicalMemory

wmic OS get TotalVisibleMemorySize /Value

Note not TotalPhysicalMemory as suggested elsewhere

沫尐诺 2025-01-08 13:21:40

SysSnternals 提供了大量有用的低级工具。

psinfo 可能是最有用的。

我使用了以下 psinfo 开关:

-h        Show installed hotfixes.
-d        Show disk volume information.

示例输出如下:

c:> psinfo \\development -h -d

PsInfo v1.6 - local and remote system information viewer
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com


System information for \\DEVELOPMENT:
Uptime: 28 days, 0 hours, 15 minutes, 12 seconds
Kernel version: Microsoft Windows XP, Multiprocessor Free
Product type Professional
Product version: 5.1
Service pack: 0
Kernel build number: 2600
Registered organization: Sysinternals
Registered owner: Mark Russinovich
Install date: 1/2/2002, 5:29:21 PM
Activation status: Activated
IE version: 6.0000
System root: C:\WINDOWS
Processors: 2
Processor speed: 1.0 GHz
Processor type: Intel Pentium III
Physical memory: 1024 MB
Volume Type Format Label Size Free Free
A: Removable 0%
C: Fixed NTFS WINXP 7.8 GB 1.3 GB 16%
D: Fixed NTFS DEV 10.7 GB 809.7 MB 7%
E: Fixed NTFS SRC 4.5 GB 1.8 GB 41%
F: Fixed NTFS MSDN 2.4 GB 587.5 MB 24%
G: Fixed NTFS GAMES 8.0 GB 1.0 GB 13%
H: CD-ROM CDFS JEDIOUTCAST 633.6 MB 0%
I: CD-ROM 0% Q: Remote 0%
T: Fixed NTFS Test 502.0 MB 496.7 MB 99%
OS Hot Fix Installed
Q147222 1/2/2002
Q309521 1/4/2002
Q311889 1/4/2002
Q313484 1/4/2002
Q314147 3/6/2002
Q314862 3/13/2002
Q315000 1/8/2002
Q315403 3/13/2002
Q317277 3/20/2002

There is a whole bunch of useful low level tools from SysSnternals.

And psinfo may be the most useful.

I used the following psinfo switches:

-h        Show installed hotfixes.
-d        Show disk volume information.

Sample output is this:

c:> psinfo \\development -h -d

PsInfo v1.6 - local and remote system information viewer
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com


System information for \\DEVELOPMENT:
Uptime: 28 days, 0 hours, 15 minutes, 12 seconds
Kernel version: Microsoft Windows XP, Multiprocessor Free
Product type Professional
Product version: 5.1
Service pack: 0
Kernel build number: 2600
Registered organization: Sysinternals
Registered owner: Mark Russinovich
Install date: 1/2/2002, 5:29:21 PM
Activation status: Activated
IE version: 6.0000
System root: C:\WINDOWS
Processors: 2
Processor speed: 1.0 GHz
Processor type: Intel Pentium III
Physical memory: 1024 MB
Volume Type Format Label Size Free Free
A: Removable 0%
C: Fixed NTFS WINXP 7.8 GB 1.3 GB 16%
D: Fixed NTFS DEV 10.7 GB 809.7 MB 7%
E: Fixed NTFS SRC 4.5 GB 1.8 GB 41%
F: Fixed NTFS MSDN 2.4 GB 587.5 MB 24%
G: Fixed NTFS GAMES 8.0 GB 1.0 GB 13%
H: CD-ROM CDFS JEDIOUTCAST 633.6 MB 0%
I: CD-ROM 0% Q: Remote 0%
T: Fixed NTFS Test 502.0 MB 496.7 MB 99%
OS Hot Fix Installed
Q147222 1/2/2002
Q309521 1/4/2002
Q311889 1/4/2002
Q313484 1/4/2002
Q314147 3/6/2002
Q314862 3/13/2002
Q315000 1/8/2002
Q315403 3/13/2002
Q317277 3/20/2002
飘然心甜 2025-01-08 13:21:40

有点旧,但我想知道类似的。只是添加我遇到的解决方案,因为 IMO 最好的答案来自 Everardo w/ 物理内存

wmic 操作系统获取 FreePhysicalMemory /Value

这让我更深入地研究 wmic...请记住,空闲物理内存不是要查看的类型。

wmic OS get FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles /VALUE

这会返回类似...

FreePhysicalMemory=2083440
FreeSpaceInPagingFiles=3636128
FreeVirtualMemory=842124

Bit old but I wanted to know similar. Just adding the solution I came across since IMO the best answer came from Everardo w/ Physical Memory

wmic OS get FreePhysicalMemory /Value

This lead me to look deeper into wmic... Keep in mind Free Physical Memory is not the type to look at.

wmic OS get FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles /VALUE

This returns something like...

FreePhysicalMemory=2083440
FreeSpaceInPagingFiles=3636128
FreeVirtualMemory=842124
妳是的陽光 2025-01-08 13:21:40
PS C:\Users\Rack> systeminfo | findstr "System Memory"
System Boot Time:          5/5/2016, 11:10:41 PM
System Manufacturer:       VMware, Inc.
System Model:              VMware Virtual Platform
System Type:               x64-based PC
System Directory:          C:\Windows\system32
System Locale:             en-us;English (United States)
Total Physical Memory:     40,959 MB
Available Physical Memory: 36,311 MB
Virtual Memory: Max Size:  45,054 MB
Virtual Memory: Available: 41,390 MB
Virtual Memory: In Use:    3,664 MB
PS C:\Users\Rack> systeminfo | findstr "System Memory"
System Boot Time:          5/5/2016, 11:10:41 PM
System Manufacturer:       VMware, Inc.
System Model:              VMware Virtual Platform
System Type:               x64-based PC
System Directory:          C:\Windows\system32
System Locale:             en-us;English (United States)
Total Physical Memory:     40,959 MB
Available Physical Memory: 36,311 MB
Virtual Memory: Max Size:  45,054 MB
Virtual Memory: Available: 41,390 MB
Virtual Memory: In Use:    3,664 MB
八巷 2025-01-08 13:21:40

发布的 wmic 命令的 Powershell 版本:

Get-CIMInstance Win32_OperatingSystem | Select *memory*

FreePhysicalMemory     : 1507688
FreeVirtualMemory      : 2131128
MaxProcessMemorySize   : 137438953344
TotalVirtualMemorySize : 13639352
TotalVisibleMemorySize : 8214848

Powershell version of the posted wmic commands:

Get-CIMInstance Win32_OperatingSystem | Select *memory*

FreePhysicalMemory     : 1507688
FreeVirtualMemory      : 2131128
MaxProcessMemorySize   : 137438953344
TotalVirtualMemorySize : 13639352
TotalVisibleMemorySize : 8214848
月朦胧 2025-01-08 13:21:40

这不能在纯java中完成。但是你可以使用java运行外部程序并得到结果。

Process p=Runtime.getRuntime().exec("systeminfo");
Scanner scan=new Scanner(p.getInputStream());
while(scan.hasNext()){
    String temp=scan.nextLine();
    if(temp.equals("Available Physical Memmory")){
       System.out.println("RAM :"temp.split(":")[1]);
       break;
    }
}

This cannot be done in pure java. But you can run external programs using java and get the result.

Process p=Runtime.getRuntime().exec("systeminfo");
Scanner scan=new Scanner(p.getInputStream());
while(scan.hasNext()){
    String temp=scan.nextLine();
    if(temp.equals("Available Physical Memmory")){
       System.out.println("RAM :"temp.split(":")[1]);
       break;
    }
}
凡尘雨 2025-01-08 13:21:40

尝试内存日志。它完美而快速地完成了这项工作。

通过多个镜像之一下载,例如这个:MemLog 的 SoftPedia 页面 .
MemLog 的作者有一个网站。但有时会关闭。回溯机快照 此处。)

示例输出:

C:\>memlog
2012/02/01,13:22:02,878956544,-1128333312,2136678400,2138578944,-17809408,2147352576

878956544 是可用内存

Try MemLog. It does the job perfectly and quickly.

Download via one of many mirrors, e.g. this one: SoftPedia page for MemLog.
(MemLog's author has a web site. But this is down some times. Wayback machine snapshot here.)

Example output:

C:\>memlog
2012/02/01,13:22:02,878956544,-1128333312,2136678400,2138578944,-17809408,2147352576

878956544 being the free memory

少女情怀诗 2025-01-08 13:21:40

实际上,这是一个纯粹的 Java 解决方案:

public static long getFreePhysicalMemory()
{
    com.sun.management.OperatingSystemMXBean bean =
            (com.sun.management.OperatingSystemMXBean)
                    java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    return bean.getFreePhysicalMemorySize();
}

Here is a pure Java solution actually:

public static long getFreePhysicalMemory()
{
    com.sun.management.OperatingSystemMXBean bean =
            (com.sun.management.OperatingSystemMXBean)
                    java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    return bean.getFreePhysicalMemorySize();
}
⒈起吃苦の倖褔 2025-01-08 13:21:40

如果您在 Java 程序中需要此功能,您可能需要查看 sigar API:http:// /www.hyperic.com/products/sigar

实际上,我知道这不是问题的答案,而是一个提示,这样您就不必重新发明轮子。

Just in case you need this functionality in a Java program, you might want to look at the sigar API: http://www.hyperic.com/products/sigar

Actually, this is no answer to the question, I know, but a hint so you don't have to reinvent the wheel.

我不会写诗 2025-01-08 13:21:40

由于问题是关于窗口命令行中的可用 RAM,因此答案如下:

c:\>wmic OS get FreePhysicalMemory 

您可以使用全局命令获取有关内存和其他内容所需的所有信息。

c:\>wmic OS

之后,您只需使用 get yourFilterName 添加过滤器

希望这会有所帮助;)

As the question was about the available RAM form a window commande line, here is the answer :

c:\>wmic OS get FreePhysicalMemory 

you can get all the information you need about memory and other things using the global commande

c:\>wmic OS

After that you'll only have the add a filter using get yourFilterName

Hope this will help ;)

猫瑾少女 2025-01-08 13:21:40

您可以通过管道将“systeminfo”传递给 grep

systeminfo | grep "Total Physical Memory"

结果如下:

Total Physical Memory:     16,249 MB 
Available Physical Memory: 9,092 MB 
Virtual Memory: Max Size:  18,681 MB 
Virtual Memory: Available: 7,978 MB 
Virtual Memory: In Use:    10,703 MB

You can pipe "systeminfo" to grep

systeminfo | grep "Total Physical Memory"

The result will be as follow:

Total Physical Memory:     16,249 MB 
Available Physical Memory: 9,092 MB 
Virtual Memory: Max Size:  18,681 MB 
Virtual Memory: Available: 7,978 MB 
Virtual Memory: In Use:    10,703 MB
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文