Package oshi.driver.linux.proc
Class ProcessStat
java.lang.Object
oshi.driver.linux.proc.ProcessStat
Utility to read process statistics from
/proc/[pid]/stat
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum corresponding to the fields in the output of/proc/[pid]/stat
static enum
Enum corresponding to the fields in the output of/proc/[pid]/statm
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
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 Summary
Modifier and TypeMethodDescriptionstatic File[]
getFileDescriptorFiles
(int pid) Gets an array of files in the /proc/{pid}/fd directory.static File[]
Gets an array of files in the /proc directory with only numeric digit filenames, corresponding to processesstatic Map<ProcessStat.PidStatM,
Long> getPidStatM
(int pid) Reads the statistics in/proc/[pid]/statm
and returns the results.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.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.Gets a map of sockets and their corresponding process ID
-
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
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.
-
getFileDescriptorFiles
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
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
Gets a map of sockets and their corresponding process ID- Returns:
- a map with socket as the key and pid as the value
-
getThreadIds
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
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
-