1 4 package com.tc.util.runtime; 5 6 class GetPid { 7 8 private GetPid() { 9 } 11 12 public static void main(String args[]) { 13 System.out.println("PID is " + getPID()); 14 } 15 16 public static int getPID() { 17 if (libOK) { return new GetPid().getPid(); } 18 throw new RuntimeException ("The JNI library did not load correctly, the stack was printed to stderr earlier"); 19 } 20 21 private native int getPid(); 22 23 private static final boolean libOK; 24 25 static { 26 boolean ok = false; 27 try { 28 System.loadLibrary("GetPid"); 29 ok = true; 30 } catch (Throwable t) { 31 t.printStackTrace(System.err); 32 System.err.println("\n***************************\njava.library.path is [" 33 + System.getProperty("java.library.path") + "]\n***************************\n"); 34 System.err.flush(); 35 } 36 37 libOK = ok; 38 } 39 40 } 41 | Popular Tags |