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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9095948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:10:00  来源:igfitidea点击:

How to retrieve available RAM from Windows command line?

windowscommand-linecmd

提问by Mike

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)?

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

回答by diggingforfire

systeminfois a command that will output system information, including available memory

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

回答by Everardo

wmic OS get FreePhysicalMemory /Value

回答by PA.

Use wmic computersystem get TotalPhysicalMemory. E.g.:

使用wmic computersystem get TotalPhysicalMemory. 例如:

C:\>wmic computersystem get TotalPhysicalMemory
TotalPhysicalMemory
4294500352

回答by noonand

wmic OS get TotalVisibleMemorySize /Value

Note not TotalPhysicalMemoryas suggested elsewhere

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

回答by Peter Lawrey

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

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

And psinfomay be the most useful.

并且psinfo可能是最有用的。

I used the following psinfo switches:

我使用了以下 psinfo 开关:

-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

回答by Jason Brennecke

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

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

wmic OS get FreePhysicalMemory /Value

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... 请记住,空闲物理内存不是要查看的类型。

wmic OS get FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles /VALUE

wmic OS get FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles /VALUE

This returns something like...

这将返回类似...

FreePhysicalMemory=2083440
FreeSpaceInPagingFiles=3636128
FreeVirtualMemory=842124

回答by Joshua Love

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

回答by Arshed

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

这不能在纯 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;
    }
}

回答by Mike

Try MemLog. It does the job perfectly and quickly.

试试 MemLog。它可以完美而快速地完成工作。

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.)

通过许多镜像之一下载,例如这个:MemLog 的 SoftPedia 页面
MemLog 的作者有一个网站。但有时会关闭。Wayback机器快照在这里。)

Example output:

示例输出:

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

878956544being the free memory

878956544成为自由记忆

回答by BullyWiiPlaza

Here is a pure Javasolution actually:

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

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