public static Long getProcessId() {
    // Try the system call first
    try {
      return new Long(CLibrary.INSTANCE.getpid());
    } catch (Throwable t) {
    }

    // Ok. The system call failed. Try another method...
    // something like '<pid>@<hostname>', at least in SUN / Oracle JVMs
    final String jvmName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();
    final int index = jvmName.indexOf('@');
    if (index < 1) {
      // part before '@' empty (index = 0) / '@' not found (index = -1)
      return null;
    }
    try {
      return Long.parseLong(jvmName.substring(0, index));
    } catch (NumberFormatException e) {
    }
    return null;
  }