Class PidFileUtil

java.lang.Object
io.deephaven.util.process.PidFileUtil

public class PidFileUtil extends Object
Utility to manipulate pid files
  • Constructor Details

    • PidFileUtil

      public PidFileUtil()
  • Method Details

    • checkAndCreatePidFileForThisProcess

      public static void checkAndCreatePidFileForThisProcess(@NotNull com.fishlib.configuration.Configuration configuration)
      Atomically create a new file, and then write this process' PID to it.
      Parameters:
      configuration - The configuration to use for property lookup
      Throws:
      IllegalStateException - If pidFile exists or cannot be created/opened
    • checkAndCreatePidFileForProcessName

      public static void checkAndCreatePidFileForProcessName(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String processName)
      Atomically create a new file, and then write this process' PID to it.
      Parameters:
      configuration - The configuration to use for property lookup
      processName - The name to be used for the per-process unique portion of the PID file's path
      Throws:
      IllegalStateException - If pidFile exists or cannot be created/opened
    • checkAndCreatePidFile

      public static void checkAndCreatePidFile(File pidFile) throws IllegalStateException
      Atomically create a new file, and then write this process' PID to it.
      Parameters:
      pidFile - the file to be checked or created
      Throws:
      IllegalStateException - If pidFile exists or cannot be created/opened
    • parseStreamForUptime

      public static String parseStreamForUptime(@NotNull InputStream ioStream, @NotNull String pidFilePath)
      Convenience method to parse the result of linux /proc/uptime command.
      Parameters:
      ioStream - An input stream holding the result of cat /proc/uptime command
      pidFilePath - The current pid file path that may need to be deleted and created new.
      Returns:
      The first part of the given stream separated by a space
    • compareFileModTimeAndSysUptime

      public static int compareFileModTimeAndSysUptime(long fileModTimeInMillis, @NotNull String uptimeSecondsAsString)
      Takes in file modified time and system uptime as a string and determines file elapsed time in same unit as system uptime. Returns the result of their comparison.
      Parameters:
      fileModTimeInMillis - The file modified time in milliseconds (result of File.lastModified())
      uptimeSecondsAsString - A double value as a string holding system uptime in seconds
      Returns:
      A value greater than 0 if file mod time is greater, 0 when equal and value lesser than 0 otherwise