简体   繁体   中英

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:

  • CPU: Intel(R) Core(TM) i3-8100 CPU @ 3.60GHZ 3.60GHZ
  • GPU: NVIDIA GeForce GTX 980 Ti 6GB
  • OS: Windows 10 PRO x64 2004

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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