]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.util/src/org/argeo/util/OS.java
1 package org
.argeo
.util
;
4 import java
.lang
.management
.ManagementFactory
;
6 /** When OS specific informations are needed. */
8 public final static OS LOCAL
= new OS();
10 private final String arch
, name
, version
;
12 /** The OS of the running JVM */
14 arch
= System
.getProperty("os.arch");
15 name
= System
.getProperty("os.name");
16 version
= System
.getProperty("os.version");
19 public String
getArch() {
23 public String
getName() {
27 public String
getVersion() {
31 public boolean isMSWindows() {
32 // only MS Windows would use such an horrendous separator...
33 return File
.separatorChar
== '\\';
36 public String
[] getDefaultShellCommand() {
38 return new String
[] { "/bin/sh", "-l", "-i" };
40 return new String
[] { "cmd.exe", "/C" };
43 public static Integer
getJvmPid() {
45 * This method works on most platforms (including Linux). Although when Java 9
46 * comes along, there is a better way: long pid =
47 * ProcessHandle.current().getPid();
50 * http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-
53 String pidAndHost
= ManagementFactory
.getRuntimeMXBean().getName();
54 return Integer
.parseInt(pidAndHost
.substring(0, pidAndHost
.indexOf('@')));