Class ProcessStat

java.lang.Object
oshi.driver.linux.proc.ProcessStat

@ThreadSafe public final class ProcessStat extends Object
Utility to read process statistics from /proc/[pid]/stat
  • Field Details

    • PROC_PID_STAT_LENGTH

      public static final int PROC_PID_STAT_LENGTH
      Constant defining the number of integer values in /proc/pid/stat. 2.6 Kernel has 44 elements, 3.3 has 47, and 3.5 has 52.
  • Method Details

    • getPidStats

      public static Triplet<String,Character,Map<ProcessStat.PidStat,Long>> getPidStats(int pid)
      Reads the statistics in /proc/[pid]/stat and returns the results.
      Parameters:
      pid - The process ID for which to fetch stats
      Returns:
      A triplet containing the process name as the first element, a character representing the process state as the second element, and an EnumMap as the third element, where the numeric values in ProcessStat.PidStat are mapped to a Long value.

      If the process doesn't exist, returns null.

    • getPidStatM

      public static Map<ProcessStat.PidStatM,Long> getPidStatM(int pid)
      Reads the statistics in /proc/[pid]/statm and returns the results.
      Parameters:
      pid - The process ID for which to fetch stats
      Returns:
      An EnumMap where the numeric values in ProcessStat.PidStatM are mapped to a Long value.

      If the process doesn't exist, returns null.

    • getFileDescriptorFiles

      public static File[] getFileDescriptorFiles(int pid)
      Gets an array of files in the /proc/{pid}/fd directory.
      Parameters:
      pid - id of process to read file descriptors for
      Returns:
      An array of File objects representing opened file descriptors of the process
    • getPidFiles

      public static File[] getPidFiles()
      Gets an array of files in the /proc directory with only numeric digit filenames, corresponding to processes
      Returns:
      An array of File objects for the process files
    • querySocketToPidMap

      public static Map<Integer,Integer> querySocketToPidMap()
      Gets a map of sockets and their corresponding process ID
      Returns:
      a map with socket as the key and pid as the value
    • getThreadIds

      public static List<Integer> getThreadIds(int pid)
      Gets a List of thread ids for a process from the /proc/[pid]/task/ directory with only numeric digit filenames, corresponding to the threads.
      Parameters:
      pid - process id
      Returns:
      A list of thread id.
    • getState

      public static OSProcess.State getState(char stateValue)
      Returns Enum STATE for the state value obtained from status file of any process/thread.
      Parameters:
      stateValue - state value from the status file
      Returns:
      OSProcess.State