code: public static int getProcessId() {
      RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
      String runtimeMxBeanName = runtimeMxBean.getName();
  
      Throwable cause = null;
  
      if (hasText(runtimeMxBeanName)) {
        int atSignIndex = runtimeMxBeanName.indexOf('@');
  
        if (atSignIndex > 0) {
          try {
            return Integer.parseInt(runtimeMxBeanName.substring(0, atSignIndex));
          }
          catch (NumberFormatException e) {
            cause = e;
          }
        }
      }
  
      throw new PidUnknownException(String.format("Process ID (PID) unknown [%s]", runtimeMxBeanName), cause);
    }
docs: Determines the Process ID (PID) of this Java {@link Process}.
  
  @return an {@link Integer} value indicating the Process ID (PID) of this Java {@link Process}.
  @throws PidUnknownException if the Process ID (PID) of this Java {@link Process} cannot be determined.