Package oshi.software.common
Class AbstractOperatingSystem
- java.lang.Object
-
- oshi.software.common.AbstractOperatingSystem
-
- All Implemented Interfaces:
OperatingSystem
- Direct Known Subclasses:
AixOperatingSystem,FreeBsdOperatingSystem,LinuxOperatingSystem,MacOperatingSystem,OpenBsdOperatingSystem,SolarisOperatingSystem,WindowsOperatingSystem
public abstract class AbstractOperatingSystem extends java.lang.Object implements OperatingSystem
Common methods for OperatingSystem implementations
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface oshi.software.os.OperatingSystem
OperatingSystem.OSVersionInfo, OperatingSystem.ProcessFiltering, OperatingSystem.ProcessSorting
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Supplier<java.lang.Integer>bitnessprivate java.util.function.Supplier<Pair<java.lang.String,OperatingSystem.OSVersionInfo>>familyVersionInfoprivate java.util.function.Supplier<java.lang.String>manufacturerprotected static booleanUSE_WHO_COMMAND
-
Constructor Summary
Constructors Constructor Description AbstractOperatingSystem()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intgetBitness()Gets the bitness (32 or 64) of the operating system.java.util.List<OSProcess>getChildProcesses(int parentPid, java.util.function.Predicate<OSProcess> filter, java.util.Comparator<OSProcess> sort, int limit)Gets currently running child processes of provided parent PID, optionally filtering, sorting, and limited to the top "N".private static java.util.Set<java.lang.Integer>getChildren(java.util.Map<java.lang.Integer,java.lang.Integer> parentPidMap, int parentPid)protected static java.util.Set<java.lang.Integer>getChildrenOrDescendants(java.util.Collection<OSProcess> allProcs, int parentPid, boolean allDescendants)Utility method for subclasses to take a full process list as input and return the children or descendants of a particular process.protected static java.util.Set<java.lang.Integer>getChildrenOrDescendants(java.util.Map<java.lang.Integer,java.lang.Integer> parentPidMap, int parentPid, boolean allDescendants)Utility method for subclasses to take a map of pid to parent as input and return the children or descendants of a particular process.java.util.List<OSProcess>getDescendantProcesses(int parentPid, java.util.function.Predicate<OSProcess> filter, java.util.Comparator<OSProcess> sort, int limit)Gets currently running processes of provided parent PID's descendants, including their children, the children's children, etc., optionally filtering, sorting, and limited to the top "N".java.lang.StringgetFamily()Get the Operating System family.java.lang.StringgetManufacturer()Get the Operating System manufacturer.java.util.List<OSProcess>getProcesses(java.util.function.Predicate<OSProcess> filter, java.util.Comparator<OSProcess> sort, int limit)Gets currently running processes, optionally filtering, sorting, and limited to the top "N".OperatingSystem.OSVersionInfogetVersionInfo()Get Operating System version information.protected abstract java.util.List<OSProcess>queryAllProcesses()protected abstract intqueryBitness(int jvmBitness)Backup OS-specific query to determine bitness if previous checks failprotected abstract java.util.List<OSProcess>queryChildProcesses(int parentPid)protected abstract java.util.List<OSProcess>queryDescendantProcesses(int parentPid)protected abstract Pair<java.lang.String,OperatingSystem.OSVersionInfo>queryFamilyVersionInfo()protected abstract java.lang.StringqueryManufacturer()private intqueryPlatformBitness()java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface oshi.software.os.OperatingSystem
getCurrentProcess, getCurrentThread, getDesktopWindows, getFileSystem, getInternetProtocolStats, getNetworkParams, getProcess, getProcessCount, getProcesses, getProcesses, getProcessId, getServices, getSessions, getSystemBootTime, getSystemUptime, getThreadCount, getThreadId, isElevated
-
-
-
-
Field Detail
-
USE_WHO_COMMAND
protected static final boolean USE_WHO_COMMAND
-
manufacturer
private final java.util.function.Supplier<java.lang.String> manufacturer
-
familyVersionInfo
private final java.util.function.Supplier<Pair<java.lang.String,OperatingSystem.OSVersionInfo>> familyVersionInfo
-
bitness
private final java.util.function.Supplier<java.lang.Integer> bitness
-
-
Method Detail
-
getManufacturer
public java.lang.String getManufacturer()
Description copied from interface:OperatingSystemGet the Operating System manufacturer.- Specified by:
getManufacturerin interfaceOperatingSystem- Returns:
- the manufacturer
-
queryManufacturer
protected abstract java.lang.String queryManufacturer()
-
getFamily
public java.lang.String getFamily()
Description copied from interface:OperatingSystemGet the Operating System family.- Specified by:
getFamilyin interfaceOperatingSystem- Returns:
- the family
-
getVersionInfo
public OperatingSystem.OSVersionInfo getVersionInfo()
Description copied from interface:OperatingSystemGet Operating System version information.- Specified by:
getVersionInfoin interfaceOperatingSystem- Returns:
- version information
-
queryFamilyVersionInfo
protected abstract Pair<java.lang.String,OperatingSystem.OSVersionInfo> queryFamilyVersionInfo()
-
getBitness
public int getBitness()
Description copied from interface:OperatingSystemGets the bitness (32 or 64) of the operating system.- Specified by:
getBitnessin interfaceOperatingSystem- Returns:
- The number of bits supported by the operating system.
-
queryPlatformBitness
private int queryPlatformBitness()
-
queryBitness
protected abstract int queryBitness(int jvmBitness)
Backup OS-specific query to determine bitness if previous checks fail- Parameters:
jvmBitness- The bitness of the JVM- Returns:
- The operating system bitness
-
getProcesses
public java.util.List<OSProcess> getProcesses(java.util.function.Predicate<OSProcess> filter, java.util.Comparator<OSProcess> sort, int limit)
Description copied from interface:OperatingSystemGets currently running processes, optionally filtering, sorting, and limited to the top "N".- Specified by:
getProcessesin interfaceOperatingSystem- Parameters:
filter- An optionalPredicatelimiting the results to the specified filter. Some common predicates are available inOperatingSystem.ProcessSorting. May benullfor no filtering.sort- An optionalComparatorspecifying the sorting order. Some common comparators are available inOperatingSystem.ProcessSorting. May benullfor no sorting.limit- Max number of results to return, or 0 to return all results- Returns:
- A list of
OSProcessobjects, optionally filtered, sorted, and limited to the specified number.The list may contain processes with a state of
OSProcess.State.INVALIDif a process terminates during iteration.
-
queryAllProcesses
protected abstract java.util.List<OSProcess> queryAllProcesses()
-
getChildProcesses
public java.util.List<OSProcess> getChildProcesses(int parentPid, java.util.function.Predicate<OSProcess> filter, java.util.Comparator<OSProcess> sort, int limit)
Description copied from interface:OperatingSystemGets currently running child processes of provided parent PID, optionally filtering, sorting, and limited to the top "N".- Specified by:
getChildProcessesin interfaceOperatingSystem- Parameters:
parentPid- The Process ID whose children to list.filter- An optionalPredicatelimiting the results to the specified filter. Some common predicates are available inOperatingSystem.ProcessSorting. May benullfor no filtering.sort- An optionalComparatorspecifying the sorting order. Some common comparators are available inOperatingSystem.ProcessSorting. May benullfor no sorting.limit- Max number of results to return, or 0 to return all results- Returns:
- A list of
OSProcessobjects representing the currently running child processes of the provided PID, optionally filtered, sorted, and limited to the specified number.The list may contain processes with a state of
OSProcess.State.INVALIDif a process terminates during iteration.
-
queryChildProcesses
protected abstract java.util.List<OSProcess> queryChildProcesses(int parentPid)
-
getDescendantProcesses
public java.util.List<OSProcess> getDescendantProcesses(int parentPid, java.util.function.Predicate<OSProcess> filter, java.util.Comparator<OSProcess> sort, int limit)
Description copied from interface:OperatingSystemGets currently running processes of provided parent PID's descendants, including their children, the children's children, etc., optionally filtering, sorting, and limited to the top "N".- Specified by:
getDescendantProcessesin interfaceOperatingSystem- Parameters:
parentPid- The Process ID whose children to list.filter- An optionalPredicatelimiting the results to the specified filter. Some common predicates are available inOperatingSystem.ProcessSorting. May benullfor no filtering.sort- An optionalComparatorspecifying the sorting order. Some common comparators are available inOperatingSystem.ProcessSorting. May benullfor no sorting.limit- Max number of results to return, or 0 to return all results- Returns:
- A list of
OSProcessobjects representing the currently running descendant processes of the provided PID, optionally filtered, sorted, and limited to the specified number.The list may contain processes with a state of
OSProcess.State.INVALIDif a process terminates during iteration.
-
queryDescendantProcesses
protected abstract java.util.List<OSProcess> queryDescendantProcesses(int parentPid)
-
getChildrenOrDescendants
protected static java.util.Set<java.lang.Integer> getChildrenOrDescendants(java.util.Collection<OSProcess> allProcs, int parentPid, boolean allDescendants)
Utility method for subclasses to take a full process list as input and return the children or descendants of a particular process. The process itself is also returned to more efficiently extract its start time for filtering- Parameters:
allProcs- A collection of all processesparentPid- The process ID whose children or descendants to returnallDescendants- If false, only gets immediate children of this process. If true, gets all descendants.- Returns:
- Set of children or descendants of parentPid
-
getChildrenOrDescendants
protected static java.util.Set<java.lang.Integer> getChildrenOrDescendants(java.util.Map<java.lang.Integer,java.lang.Integer> parentPidMap, int parentPid, boolean allDescendants)Utility method for subclasses to take a map of pid to parent as input and return the children or descendants of a particular process.- Parameters:
parentPidMap- a map of all processes with processID as key and parentProcessID as valueparentPid- The process ID whose children or descendants to returnallDescendants- If false, only gets immediate children of this process. If true, gets all descendants.- Returns:
- Set of children or descendants of parentPid, including the parent
-
getChildren
private static java.util.Set<java.lang.Integer> getChildren(java.util.Map<java.lang.Integer,java.lang.Integer> parentPidMap, int parentPid)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-