com.bigdata.counters
Class PIDUtil

java.lang.Object
  extended by com.bigdata.counters.PIDUtil

public class PIDUtil
extends Object

Utility to return the PID of the JVM.

Version:
$Id: PIDUtil.java 4084 2011-01-13 15:57:45Z thompsonbry $
Author:
Bryan Thompson

Constructor Summary
PIDUtil()
           
 
Method Summary
static int getLinuxPIDWithBash()
          Return the PID of the Java VM under Linux using bash.
static int getPID()
          Tries each of the methods in this class and returns the PID as reported by the first method that succeeds.
static int getPIDWithRuntimeMXBean()
          Return the JVM PID.
static void main(String[] args)
          Utility for checking which method works on your platform.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PIDUtil

public PIDUtil()
Method Detail

getLinuxPIDWithBash

public static int getLinuxPIDWithBash()
Return the PID of the Java VM under Linux using bash.

Returns:
The PID.
Throws:
RuntimeException - if anything goes wrong.

getPIDWithRuntimeMXBean

public static int getPIDWithRuntimeMXBean()
Return the JVM PID.

Throws:
UnsupportedOperationException - if the pid can not be extracted.
See Also:
RuntimeMXBean#getName(), A web search will show that this is generally of the form "pid@host". However this is definitely NOT guaranteed by the javadoc.

getPID

public static int getPID()
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.

Returns:
The PID of this JVM (best guess).

main

public static void main(String[] args)
                 throws InterruptedException
Utility for checking which method works on your platform.

Parameters:
args -
Throws:
InterruptedException


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.