简体   繁体   中英

Determine linux version from java

I'm wondering if there's a way to determine which version of Linux I'm running (ie differentiate between RHEL4, RHEL5) from within the JVM. I'm just looking for a consistent way to differentiate between the operating systems and their versions.

The JVM gives you some basic information about the operating system via

System.getProperty()

"os.name" // OS name
"os.arch" // OS architecture
"os.version" // OS version

As far as I know it doesn't offers distribution specific information. At least for debian distributions this information is stored in a file called

/etc/issue

So it may help reading any of the files where the different distros store this information.

I do not believe there are any system properties you can look at that will give you that information. How about just executing a cat /proc/version and parsing the output.

Which version of the distro you're running or which version of the Kernel? I know that Red Hat used to keep their version number in a file called /etc/redhat-release. I'm not sure for the other distro's. You can get the kernel version by doing a system call on "uname -r"

/prov/version is a good start. /etc/issue might also be helpful.

如果System.getProperty(x)其中x是“os.name”,“os.arch”,“os.version”对你不起作用,那么你可能不得不求助于按照建议运行本机进程(cat / proc / version,或lsb_release等)

You can also have a look at lsb_release

lsb_release -a

would give you something like:

cyril@merlin:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 8.10
Release:    8.10
Codename:   intrepid

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