Class ProcessStat

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

@ThreadSafe
public final class ProcessStat
extends java.lang.Object
Utility to read process statistics from /proc/[pid]/stat
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  ProcessStat.PidStat
    Enum corresponding to the fields in the output of /proc/[pid]/stat
    static class  ProcessStat.PidStatM
    Enum corresponding to the fields in the output of /proc/[pid]/statm
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int PROC_PID_STAT_LENGTH
    Constant defining the number of integer values in /proc/pid/stat.
  • Method Summary

    Modifier and Type Method Description
    static java.io.File[] getPidFiles()
    Gets an array of files in the /proc directory with only numeric digit filenames, corresponding to processes
    static java.util.Map<ProcessStat.PidStatM,​java.lang.Long> getPidStatM​(int pid)
    Reads the statistics in /proc/[pid]/statm and returns the results.
    static Triplet<java.lang.String,​java.lang.Character,​java.util.Map<ProcessStat.PidStat,​java.lang.Long>> getPidStats​(int pid)
    Reads the statistics in /proc/[pid]/stat and returns the results.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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<java.lang.String,​java.lang.Character,​java.util.Map<ProcessStat.PidStat,​java.lang.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 java.util.Map<ProcessStat.PidStatM,​java.lang.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.

    • getPidFiles

      public static java.io.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