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.

3
  • check this link stackoverflow.com/questions/25552/… Commented Apr 8, 2014 at 12:58
  • But in the link you passed me, i got memory size, not the cpu type. Commented Apr 8, 2014 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". Commented Apr 8, 2014 at 18:42

2 Answers 2

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"));        
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.