01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.util.runtime;
06:
07: import com.tc.test.TestConfigObject;
08:
09: import java.io.File;
10:
11: class GetPid {
12:
13: private GetPid() {
14: // nothing here
15: }
16:
17: public static void main(String args[]) {
18: System.out.println("PID is " + getPID());
19: }
20:
21: public static int getPID() {
22: if (libOK) {
23: return new GetPid().getPid();
24: }
25: throw new RuntimeException(
26: "The JNI library did not load correctly, the stack was printed to stderr earlier");
27: }
28:
29: private native int getPid();
30:
31: private static final boolean libOK;
32:
33: static {
34: boolean ok = false;
35: String nativeLibPath = TestConfigObject.getInstance()
36: .executableSearchPath()
37: + File.separator
38: + TestConfigObject.getInstance().nativeLibName();
39: try {
40: System.load(nativeLibPath);
41: ok = true;
42: } catch (Throwable t) {
43: t.printStackTrace(System.err);
44: System.err
45: .println("\n***************************\nNative lib path is ["
46: + nativeLibPath
47: + "]\n***************************\n");
48: System.err.flush();
49: }
50:
51: libOK = ok;
52: }
53:
54: }
|