3

I want to retrieve a procesor tipe in java program(like "Ivy bridge").I look for some Sytem comand like:

System.out.println(System.getenv("PROCESSOR_IDENTIFIER"));
System.out.println(System.getenv("PROCESSOR_ARCHITECTURE"));
System.out.println(System.getenv("PROCESSOR_ARCHITEW6432"));
System.out.println(System.getenv("NUMBER_OF_PROCESSORS"));

but i don't find what i want.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Sceik
  • 275
  • 1
  • 3
  • 13
  • check this link http://stackoverflow.com/questions/25552/using-java-to-get-os-level-system-information – Shriram Apr 08 '14 at 12:58
  • But in the link you passed me, i got memory size, not the cpu type. – Sceik Apr 08 '14 at 13:04
  • You won't get "Ivy Bridge" back no matter what. It's Intel's codename for the architecture, not a product identifier. Programmatically available CPU descriptions tend to be more along the lines of "Core 2 E3500". – Seva Alekseyev Apr 08 '14 at 18:42

2 Answers2

2

You can query the registry. This can be done easily with JNA. Works for Windows only.

import com.sun.jna.platform.win32.Advapi32Util;
import static com.sun.jna.platform.win32.WinReg.HKEY_LOCAL_MACHINE;

    public class GetCPUInfosUsingJNA {

        // https://github.com/twall/jna#readme
        //  you need 2 jars : jna-3.5.1.jar and platform-3.5.1.jar

        public static void main(String ... args) {
          System.out.println(Advapi32Util.registryGetStringValue
             (HKEY_LOCAL_MACHINE,
                "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\\",
              "ProcessorNameString"));   
          System.out.println(Advapi32Util.registryGetStringValue
                  (HKEY_LOCAL_MACHINE,
                     "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\\",
                   "Identifier"));        
        }
    }
RealHowTo
  • 34,977
  • 11
  • 70
  • 85
1

If you are using windows use jawin to access win32 api and for linux distributions read /proc/cpuinfo and parse it.

Shriram
  • 4,343
  • 8
  • 37
  • 64