4

At the beginning I want to mention that this is not duplicate of this topic.

I know that I can check OS I'm running from Java, programmatically via System.getProperty("os.name");

My question is: How Java determine my operating system? Other words, when Properties are loaded/set (especially os.name) and what command is run to do so?

UPDATE

Not a duplicate of Where (which properties file) does System.getProperty(“key”) reads from? aswell. Im not asking for a place where properties are storaged. Im asking for command that are used to determine OS name.

As @Phylogenesis commented - on Windows it is used a GetVersionEx inside in native c implementation.

What about Unix/Linux?

Community
  • 1
  • 1
countryroadscat
  • 1,660
  • 4
  • 26
  • 49
  • Most likely an OS-specific command, issued from the OS-specific implementation of JAVA? – TT. Oct 26 '16 at 12:17
  • @TT. Probably. However can I check somewhere what command are used? – countryroadscat Oct 26 '16 at 12:19
  • 1
    In particular, see the answers in [this question](https://stackoverflow.com/questions/31909107/javas-os-name-for-windows-10) for more details about how `System.getProperty("os.name")` is generated. – Phylogenesis Oct 26 '16 at 12:20
  • @ArcticLord I dont think so, Im asking for some kind OS-specific method, not implementation details – countryroadscat Oct 26 '16 at 12:21
  • Well that entirely depends on the OS on which JAVA is running on. Each OS has a different function to obtain this information. Java uses JNI to call that OS specific function. So the "command" is different on each OS. – TT. Oct 26 '16 at 12:25

1 Answers1

4

Simply have a look into the OpenJDK source code.

ArcticLord
  • 3,999
  • 3
  • 27
  • 47