Package oshi.driver.linux.proc
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 processesstatic 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.static OSProcess.State
getState(char stateValue)
Returns Enum STATE for the state value obtained from status file of any process/thread.static java.util.List<java.lang.Integer>
getThreadIds(int pid)
Gets an List of thread ids for a process from the/proc/[pid]/task/
directory with only numeric digit filenames, corresponding to the threads.
-
Field Details
-
PROC_PID_STAT_LENGTH
public static final int PROC_PID_STAT_LENGTHConstant 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 aLong
value.If the process doesn't exist, returns null.
-
getPidStatM
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 aLong
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
-
getThreadIds
public static java.util.List<java.lang.Integer> getThreadIds(int pid)Gets an 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
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
-