Class AbstractOSProcess
- All Implemented Interfaces:
OSProcess
- Direct Known Subclasses:
AixOSProcess, DragonFlyBsdOSProcess, FreeBsdOSProcess, LinuxOSProcess, MacOSProcessJNA, NetBsdOSProcess, OpenBsdOSProcess, SolarisOSProcess, WindowsOSProcess
-
Nested Class Summary
Nested classes/interfaces inherited from interface OSProcess
OSProcess.StateModifier and TypeInterfaceDescriptionstatic enumProcess and Thread Execution States -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractOSProcess(int pid) Creates an AbstractOSProcess for the given process ID. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetProcessCpuLoadBetweenTicks(OSProcess priorSnapshot) Gets CPU usage of this process since a previous snapshot of the same process, provided as a parameter.doubleGets cumulative CPU usage of this process.intGets the process ID.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface OSProcess
getAffinityMask, getArguments, getBitness, getBytesRead, getBytesWritten, getCommandLine, getContextSwitches, getCurrentWorkingDirectory, getEnvironmentVariables, getGroup, getGroupID, getHardOpenFileLimit, getInvoluntaryContextSwitches, getKernelTime, getMajorFaults, getMinorFaults, getName, getOpenFiles, getParentProcessID, getPath, getPriority, getPrivateResidentMemory, getResidentMemory, getSoftOpenFileLimit, getStartTime, getState, getThreadCount, getThreadDetails, getUpTime, getUser, getUserID, getUserTime, getVirtualSize, getVoluntaryContextSwitches, updateAttributesModifier and TypeMethodDescriptionlongGets the process affinity mask for this process.Makes a best effort attempt to get a list of the the command-line arguments of the process.intAttempts to get the bitness (32 or 64) of the process.longGets the bytes read by the process.longGets the bytes written by the process.Gets the process command line used to start the process, including arguments if available to be determined.default longA snapshot of the context switches the process has done, equal to the sum ofOSProcess.getVoluntaryContextSwitches()andOSProcess.getInvoluntaryContextSwitches()on platforms that provide the split.Makes a best effort attempt to obtain the current working directory for the process.Makes a best effort attempt to obtain the environment variables of the process.getGroup()Gets the group under which the process is executing.Gets the group id under which the process is executing.longGets the hard limit for open file handles (or network connections) that belong to the given process.default longThe number of involuntary context switches the process has made.longGets kernel/system (privileged) time used by the process.default longGets the number of major (hard) faults the process has made which have required loading a memory page from disk.default longGets the number of minor (soft) faults the process has made which have not required loading a memory page from disk.getName()Gets the name of the process, often the executable program.longGets the number of open file handles (or network connections) that belongs to the process.intGets the process ID of this process's parent.getPath()Gets the full filesystem path of the executing process.intGets the priority of this process.default longReturns an estimate of the portion of physical memory (RAM) uniquely attributed to this process.longReturns the total amount of physical memory (RAM) currently mapped to the process's address space.longGets the soft limit for open file handles (or network connections) of the given process.longGets the process start time.getState()Gets the process state.intGets the number of threads being executed by this process.Retrieves the threads of the process and their details.longGets up time / elapsed time since the process started.getUser()Gets the user name of the process owner.Gets the user id of the process owner.longGets user time used by the process.longGets the Virtual Memory Size (VSZ).default longThe number of voluntary context switches the process has made.booleanAttempts to update process attributes.
-
Constructor Details
-
AbstractOSProcess
protected AbstractOSProcess(int pid) Creates an AbstractOSProcess for the given process ID.- Parameters:
pid- the process ID
-
-
Method Details
-
getProcessID
public int getProcessID()Description copied from interface:OSProcessGets 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:
getProcessIDin interfaceOSProcess- Returns:
- the processID.
-
getProcessCpuLoadCumulative
public double getProcessCpuLoadCumulative()Description copied from interface:OSProcessGets 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:
getProcessCpuLoadCumulativein interfaceOSProcess- Returns:
- The proportion of up time that the process was executing in kernel or user mode.
-
getProcessCpuLoadBetweenTicks
Description copied from interface:OSProcessGets 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 calculations 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.
Usage example:
Map<Integer, OSProcess> priorSnapshot = new HashMap<>(); while (monitoring) { for (OSProcess p : os.getProcesses(null, null, 0)) { double cpu = p.getProcessCpuLoadBetweenTicks(priorSnapshot.get(p.getProcessID())); priorSnapshot.put(p.getProcessID(), p); } Thread.sleep(2000); }- Specified by:
getProcessCpuLoadBetweenTicksin interfaceOSProcess- Parameters:
priorSnapshot- AnOSProcessobject 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
-