iamjustcoder
iamjustcoder

Reputation: 4852

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

Does any one knows very straight approach for getting these information.

Thanks in advance Viswanathan G

Upvotes: 6

Views: 7070

Answers (4)

Kashyap
Kashyap

Reputation: 17546

For CPU try org.hyperic.sigar.cmd.CpuInfo. For OS try System.getProperties().

Upvotes: 9

Rostislav Matl
Rostislav Matl

Reputation: 4553

I'd just call some native command for that. On Linux it is cat /proc/cpuinfo.

Java is not good tool for this purpose but still can easily collect information from such native tools/calls.

Upvotes: 0

Voo
Voo

Reputation: 30245

On Windows you could use WMI to get the necessary information by simply executing a (or several) simple scripts.

On linux you can do something similar by parsing information out of proc/cpuinfo and other stuff (not an expert there).

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.

Upvotes: 1

Daniel Pryden
Daniel Pryden

Reputation: 60997

I'm pretty certain there's no way to do this in pure Java. You'll need to use JNI or some other native-code interface to get information from the underlying OS. Unfortunately, this will also make your Java program not portable to other operating systems.

Upvotes: 0

Related Questions