简体   繁体   English

在java中检索CPU信息

[英]Retrieving CPU information in java

I need to write a small client application which gives CPU information such as CPU_TYPE, Processor_Speed, Serial number, UUID, operating system, physical memory and etc... 我需要编写一个小型客户端应用程序,它提供CPU信息,如CPU_TYPE,Processor_Speed,序列号,UUID,操作系统,物理内存等......

Does any one knows very straight approach for getting these information. 有没有人知道获取这些信息的非常直接的方法。

Thanks in advance Viswanathan G 在此先感谢Viswanathan G.

For CPU try this . 对于CPU试试这个 For OS try this . 对于OS试试这个

I'm pretty certain there's no way to do this in pure Java. 我很确定在纯Java中无法做到这一点。 You'll need to use JNI or some other native-code interface to get information from the underlying OS. 您需要使用JNI或其他一些本机代码接口从底层操作系统获取信息。 Unfortunately, this will also make your Java program not portable to other operating systems. 不幸的是,这也会使您的Java程序无法移植到其他操作系统。

On Windows you could use WMI to get the necessary information by simply executing a (or several) simple scripts. 在Windows上,您可以通过简单地执行一个(或几个)简单脚本来使用WMI来获取必要的信息。

On linux you can do something similar by parsing information out of proc/cpuinfo and other stuff (not an expert there). 在linux上你可以通过解析proc/cpuinfo和其他东西(不是那里的专家)的信息来做类似的事情。

minimal example for win 胜利的最小例子

I'm not aware of any framework that is crossplatform for this kind of information - mostly because there's just no way to get this information without delving deep into the platforms insides. 我不知道有任何框架是这种信息的跨平台 - 主要是因为没有深入研究内部平台就无法获得这些信息。 Depending on how much data you need you may get by by parsing the data from some trivial scripts or you could use frameworks for all platforms you need. 根据您需要的数据量,您可以通过从一些简单的脚本解析数据来获得,或者您可以将框架用于您需要的所有平台。

I'd just call some native command for that. 我只是为此调用一些本机命令。 On Linux it is cat /proc/cpuinfo . 在Linux上它是cat /proc/cpuinfo

Java is not good tool for this purpose but still can easily collect information form such native tools/calls. Java不是用于此目的的好工具,但仍可以轻松地从这些本机工具/调用中收集信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM