Class AbstractOSProcess
- java.lang.Object
-
- oshi.software.common.AbstractOSProcess
-
- All Implemented Interfaces:
OSProcess
- Direct Known Subclasses:
AixOSProcess
,FreeBsdOSProcess
,LinuxOSProcess
,MacOSProcess
,OpenBsdOSProcess
,SolarisOSProcess
,WindowsOSProcess
@ThreadSafe public abstract class AbstractOSProcess extends java.lang.Object implements OSProcess
A process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface oshi.software.os.OSProcess
OSProcess.State
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Supplier<java.lang.Double>
cumulativeCpuLoad
private int
processID
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractOSProcess(int pid)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getProcessCpuLoadBetweenTicks(OSProcess priorSnapshot)
Gets CPU usage of this process since a previous snapshot of the same process, provided as a parameter.double
getProcessCpuLoadCumulative()
Gets cumulative CPU usage of this process.int
getProcessID()
Gets the process ID.private double
queryCumulativeCpuLoad()
java.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface oshi.software.os.OSProcess
getAffinityMask, getArguments, getBitness, getBytesRead, getBytesWritten, getCommandLine, getContextSwitches, getCurrentWorkingDirectory, getEnvironmentVariables, getGroup, getGroupID, getHardOpenFileLimit, getKernelTime, getMajorFaults, getMinorFaults, getName, getOpenFiles, getParentProcessID, getPath, getPriority, getResidentSetSize, getSoftOpenFileLimit, getStartTime, getState, getThreadCount, getThreadDetails, getUpTime, getUser, getUserID, getUserTime, getVirtualSize, updateAttributes
-
-
-
-
Method Detail
-
getProcessID
public int getProcessID()
Description copied from interface:OSProcess
Gets the process ID.While this is a 32-bit value, it is unsigned on Windows and in extremely rare circumstances may return a negative value.
- Specified by:
getProcessID
in interfaceOSProcess
- Returns:
- the processID.
-
getProcessCpuLoadCumulative
public double getProcessCpuLoadCumulative()
Description copied from interface:OSProcess
Gets cumulative CPU usage of this process.This calculation sums CPU ticks across all processors and may exceed 100% for multi-threaded processes. This is consistent with the cumulative CPU presented by the "top" command on Linux/Unix machines.
- Specified by:
getProcessCpuLoadCumulative
in interfaceOSProcess
- Returns:
- The proportion of up time that the process was executing in kernel or user mode.
-
queryCumulativeCpuLoad
private double queryCumulativeCpuLoad()
-
getProcessCpuLoadBetweenTicks
public double getProcessCpuLoadBetweenTicks(OSProcess priorSnapshot)
Description copied from interface:OSProcess
Gets CPU usage of this process since a previous snapshot of the same process, provided as a parameter.This calculation sums CPU ticks across all processors and may exceed 100% for multi-threaded processes. This is consistent with process usage calulations on Linux/Unix machines, but should be divided by the number of logical processors to match the value displayed by the Windows Task Manager.
The accuracy of this calculation is dependent on both the number of threads on which the process is executing, and the precision of the Operating System's tick counters. A polling interval of at least a few seconds is recommended.
- Specified by:
getProcessCpuLoadBetweenTicks
in interfaceOSProcess
- Parameters:
priorSnapshot
- AnOSProcess
object containing statistics for this same process collected at a prior point in time. May be null.- Returns:
- If the prior snapshot is for the same process at a prior point in time, the proportion of elapsed up time between the current process snapshot and the previous one that the process was executing in kernel or user mode. Returns cumulative load otherwise.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-