private void writePid(final boolean force) throws FileAlreadyExistsException, IOException {
    if (pidFile.exists()) {
      if (!force) {
        checkOtherPid(readOtherPid());
      }
      pidFile.delete();
    }

    File tempPidFile = new File(pidFile.getParent(), pidFile.getName() + ".tmp");
    tempPidFile.createNewFile();

    logger.info("Writing process id {} to {}.", pid, pidFile);

    try (FileWriter writer = new FileWriter(tempPidFile)) {
      writer.write(String.valueOf(pid));
      writer.flush();
    }

    tempPidFile.renameTo(pidFile);
    pidFile.deleteOnExit();
  }
Creates a new pid file and writes this process's pid into it.

@param force if true then the pid file will be replaced if it already exists it

@throws FileAlreadyExistsException if the pid file already exists and force is false
@throws IOException if unable to create or write to the file
geode-core/src/main/java/org/apache/geode/internal/process/LocalProcessLauncher.java