简体   繁体   English

从java确定linux版本

[英]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. 我想知道是否有办法确定我在JVM中运行的Linux版本(即区分RHEL4,RHEL5)。 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 JVM为您提供有关操作系统的一些基本信息

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 至少对于debian发行版,这些信息存储在一个名为的文件中

/etc/issue 在/ etc /问题

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. 如何执行cat /proc/version并解析输出。

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. 我知道Red Hat曾经将他们的版本号保存在名为/ 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" 您可以通过对“uname -r”进行系统调用来获取内核版本

/prov/version is a good start. /prov/version是一个好的开始。 /etc/issue might also be helpful. /etc/issue也可能有帮助。

如果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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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