Package io.deephaven.util.process
Class PidFileUtil
java.lang.Object
io.deephaven.util.process.PidFileUtil
Utility to manipulate pid files
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkAndCreatePidFile
(File pidFile) Atomically create a new file, and then write this process' PID to it.static void
checkAndCreatePidFileForProcessName
(com.fishlib.configuration.Configuration configuration, String processName) Atomically create a new file, and then write this process' PID to it.static void
checkAndCreatePidFileForThisProcess
(com.fishlib.configuration.Configuration configuration) Atomically create a new file, and then write this process' PID to it.static int
compareFileModTimeAndSysUptime
(long fileModTimeInMillis, String uptimeSecondsAsString) Takes in file modified time and system uptime as a string and determines file elapsed time in same unit as system uptime.static String
parseStreamForUptime
(InputStream ioStream, String pidFilePath) Convenience method to parse the result of linux /proc/uptime command.
-
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 lookupprocessName
- 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
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 commandpidFilePath
- 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
-