Krystek
Krystek

Reputation: 35

How to get cpu, gpu and os full name

Is it possible to get the full name of CPU, GPU and OS in Java?

For example:

Upvotes: 2

Views: 1672

Answers (2)

rzwitserloot
rzwitserloot

Reputation: 103717

System.getProperty("os.arch") gets you something like x86_64.

System.getProperty("os.name") gets you something like Mac OS X.

System.getProperty("sun.cpu.endian") gets you little (and this is a non-standard property name).

Beyond that, the answer is mostly 'no, you cant do that'.

What you can do is check which OS you are on, and launch OS and architecture specific tools, either via the native interface (JNI) or by using ProcessBuilder to execute command line tools that are known to be installed by default on the OS you're on to get this information.

For example, IF you know you're on some posix installation (for example, mac, or linux), you can use processbuilder to run /usr/bin/uname -a, which gets you something like:

Darwin YourSystemName.local 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64

You can run /usr/sbin/sysctl -n machdep.cpu.brand_string to get something like Intel(R) Core(TM) i7-1060NG7 CPU @ 1.20GHz.

However, /usr/sbin/sysctl may not be on your system. It definitely won't be there on a windows box, it may not be there on various flavours of linux.

Trying to test such a setup is going to be extremely tricky. You'd need hundreds of deployments (all flavours of linux you care to support, various mac versions, a bunch of windows versions, and more).

Quite the complex project, in other words!

I'd consider using a library that took care of all this, such as OSHI. OSHI is a free JNA-based (native) Operating System and Hardware Information library for Java.

Upvotes: 4

vaibhav0228
vaibhav0228

Reputation: 49

I have recently used the OSHI api https://github.com/oshi/oshi it provides you many api for getting the details related to CPU information and OS.

One more alternative is SIGAR API by Hyperic.

Upvotes: 2

Related Questions