Mike
Mike

Reputation: 2396

How to retrieve available RAM from Windows command line?

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

Upvotes: 38

Views: 146315

Answers (14)

samivic
samivic

Reputation: 1310

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

Upvotes: 1

Mohamed FAIDA
Mohamed FAIDA

Reputation: 156

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

Upvotes: 1

js2010
js2010

Reputation: 27606

Powershell version of the posted wmic commands:

Get-CIMInstance Win32_OperatingSystem | Select *memory*

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

Upvotes: 3

BullyWiiPlaza
BullyWiiPlaza

Reputation: 19233

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();
}

Upvotes: 2

Mike
Mike

Reputation: 2396

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

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533870

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

Upvotes: 10

Jason Brennecke
Jason Brennecke

Reputation: 91

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

Upvotes: 9

Joshua Love
Joshua Love

Reputation: 79

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

Upvotes: 7

PA.
PA.

Reputation: 29369

Use wmic computersystem get TotalPhysicalMemory. E.g.:

C:\>wmic computersystem get TotalPhysicalMemory
TotalPhysicalMemory
4294500352

Upvotes: 24

Everardo
Everardo

Reputation: 351

wmic OS get FreePhysicalMemory /Value

Upvotes: 35

Arshed
Arshed

Reputation: 341

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;
    }
}

Upvotes: 2

noonand
noonand

Reputation: 2865

wmic OS get TotalVisibleMemorySize /Value

Note not TotalPhysicalMemory as suggested elsewhere

Upvotes: 12

skomp
skomp

Reputation: 459

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.

Upvotes: 1

diggingforfire
diggingforfire

Reputation: 3399

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

Upvotes: 47

Related Questions