简体   繁体   English

如何使用从Java到Windows OS的系统调用来查找可用的系统内存,磁盘空间,CPU使用率

[英]how to find available system memory, disk space, cpu usage using system calls from java to windows OS

how to find available system memory, disk space, cpu usage of windows OS using system calls from java? 如何使用Java中的系统调用找到Windows OS的可用系统内存,磁盘空间,CPU使用率?

*in windows operating system *在Windows操作系统中

wat i actually want to do is ,,, accept a file from client user and save the file in the server after checking the available space. 我实际上想做的是,从客户端用户接受文件,并在检查可用空间后将文件保存在服务器中。 my server and client are connected using a java tcp socket program! 我的服务器和客户端使用java tcp套接字程序连接!

You can get some limited information using the below program. 您可以使用以下程序获得一些有限的信息。 This was already answered by some one else in the same forum and I am just reproducing the same. 在同一个论坛中,其他人已经回答了这个问题,而我只是在复制相同的内容。

import java.io.File;

public class MemoryInfo {
  public static void main(String[] args) {
    /* Total number of processors or cores available to the JVM */
    System.out.println("Available processors (cores): " + 
        Runtime.getRuntime().availableProcessors());

    /* Total amount of free memory available to the JVM */
    System.out.println("Free memory (bytes): " + 
        Runtime.getRuntime().freeMemory());

    /* This will return Long.MAX_VALUE if there is no preset limit */
    long maxMemory = Runtime.getRuntime().maxMemory();
    /* Maximum amount of memory the JVM will attempt to use */
    System.out.println("Maximum memory (bytes): " + 
        (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));

    /* Total memory currently in use by the JVM */
    System.out.println("Total memory (bytes): " + 
        Runtime.getRuntime().totalMemory());

    /* Get a list of all filesystem roots on this system */
    File[] roots = File.listRoots();

    /* For each filesystem root, print some info */
    for (File root : roots) {
      System.out.println("File system root: " + root.getAbsolutePath());
      System.out.println("Total space (bytes): " + root.getTotalSpace());
      System.out.println("Free space (bytes): " + root.getFreeSpace());
      System.out.println("Usable space (bytes): " + root.getUsableSpace());
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅提供主机名,登录用户名和密码的远程系统的可用系统内存,磁盘空间,CPU使用率是否可​​行? - Is it feasible to get available system memory, disk space, cpu usage of a remote system only providing host name, Login UserId and Password Java:如何确定1.6之前的Windows系统上的磁盘空间 - Java : how to determine disk space on Windows system prior to 1.6 如何从Java获取系统负载/ CPU使用率? - How can I get system load/cpu usage from Java? 如何在没有任何存根文件的情况下获得CPU使用,远程系统中可用的内存 - How to get cpu usage, memory available in remote system without any stub file 使用Java程序查找虚拟机的CPU、磁盘和memory用法 - Find CPU, disk and memory usuage of a virtual machine using Java Program 如何使用Java程序或JMX获取远程计算机的系统总CPU使用率百分比 - How to get a System's total CPU usage percentage of a remote computer using a java program or JMX Java memory 映射文件来自 Windows 系统 - Java memory Mapped File from Windows system 如何从java获取OS的CPU使用百分比 - How to get percentage of CPU usage of OS from java 如何从 Java 获取可用磁盘空间 *IN A FOLDER* - How to Get Available Disk Space *IN A FOLDER* from Java 如何在 Java 中监控计算机的 CPU、内存和磁盘使用情况? - How do I monitor the computer's CPU, memory, and disk usage in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM