/** * Tries each of the methods in this class and returns the PID as reported * by the first method that succeeds. The order in which the methods are * tried SHOULD reflect the likelyhood that the method will get it right. * * @return The PID of this JVM (best guess). */ public static int getPID() { try { if (!SystemUtil.operatingSystem().toLowerCase().startsWith("win")) { return getLinuxPIDWithBash(); } } catch (Throwable t) { log.warn(t); } return getPIDWithRuntimeMXBean(); }
/** * Tries each of the methods in this class and returns the PID as reported * by the first method that succeeds. The order in which the methods are * tried SHOULD reflect the likelyhood that the method will get it right. * * @return The PID of this JVM (best guess). */ public static int getPID() { try { if (!SystemUtil.operatingSystem().toLowerCase().startsWith("win")) { return getLinuxPIDWithBash(); } } catch (Throwable t) { log.warn(t); } return getPIDWithRuntimeMXBean(); }
public void testSystemUtil() { System.out.println( "Number of Processors: " + SystemUtil.numProcessors() ); System.out.println( "CPU Info: " + SystemUtil.cpuInfo() ); System.out.println( "Architecture: " + SystemUtil.architecture() ); System.out.println( "Operating System: " + SystemUtil.operatingSystem() ); System.out.println( "OS Version: " + SystemUtil.osVersion() ); assertEquals( SystemUtil.architecture(), System.getProperty( "os.arch" ) ); assertEquals( SystemUtil.operatingSystem(), System.getProperty( "os.name" ) ); assertEquals( SystemUtil.osVersion(), System.getProperty( "os.version" ) ); } }