private static int getIotdbPid() {
    int iotdbPid = -1;
    Process pro1;
    Runtime r = Runtime.getRuntime();
    // System.getProperty("os.name") can detect which type of OS is using now.
    // this code can detect Windows, Mac, Unix and Solaris.
    String os = System.getProperty("os.name");
    String osName = os.toLowerCase();
    if (osName.startsWith(LINUX_OS_NAME) || osName.startsWith(MAC_OS_NAME)) {
      try {
        String command;
        if (osName.startsWith(LINUX_OS_NAME)) {
          command = String.format(SEARCH_PID_LINUX, IOTDB_PROCESS_KEY_WORD);
        } else {
          command = String.format(SEARCH_PID_MAC, IOTDB_PROCESS_KEY_WORD);
        }
        COMMAND_TEMPLATE[2] = command;
        pro1 = r.exec(COMMAND_TEMPLATE);
        BufferedReader in1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()));
        String line;
        while ((line = in1.readLine()) != null) {
          line = line.trim();
          String[] temp = line.split("\\s+");
          if (temp.length > 1 && isNumeric(temp[1])) {
            iotdbPid = Integer.parseInt(temp[1]);
            break;
          }
        }
        in1.close();
        pro1.destroy();
      } catch (IOException e) {
        LOGGER.error("Cannot get PID of IoTDB process because ", e);
      }
    } else {
      LOGGER.warn("Unsupported OS {} for OpenFileNumUtil to get the PID of IoTDB.", os);
    }
    return iotdbPid;
  }
get IoTDB server process ID by executing command.

@return pid of IoTDB server process
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/OpenFileNumUtil.java