KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > runtime > GetPid


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.util.runtime;
5
6 class GetPid {
7
8   private GetPid() {
9     // nothing here
10
}
11
12   public static void main(String JavaDoc 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 JavaDoc("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 JavaDoc 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