Package oshi.software.common
Class AbstractOperatingSystem
java.lang.Object
oshi.software.common.AbstractOperatingSystem
- All Implemented Interfaces:
OperatingSystem
- Direct Known Subclasses:
FreeBsdOperatingSystem
,LinuxOperatingSystem
,MacOperatingSystem
,SolarisOperatingSystem
,WindowsOperatingSystem
public abstract class AbstractOperatingSystem extends java.lang.Object implements OperatingSystem
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractOperatingSystem.FamilyVersionInfo
Nested classes/interfaces inherited from interface oshi.software.os.OperatingSystem
OperatingSystem.OSVersionInfo, OperatingSystem.ProcessSort
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
OSHI_OS_UNIX_WHOCOMMAND
protected static boolean
USE_WHO_COMMAND
protected OperatingSystemVersion
version
-
Constructor Summary
Constructors Constructor Description AbstractOperatingSystem()
-
Method Summary
Modifier and Type Method Description int
getBitness()
Gets the bitness (32 or 64) of the operating system.java.lang.String
getFamily()
Operating system family.java.lang.String
getManufacturer()
Manufacturer.OSProcess
getProcess(int pid)
Gets information on a currently running processOSProcess[]
getProcesses()
Gets currently running processes.OSProcess[]
getProcesses(int limit, OperatingSystem.ProcessSort sort)
Gets currently running processes, optionally limited to the top "N" for a particular sorting order.java.util.List<OSProcess>
getProcesses(java.util.Collection<java.lang.Integer> pids)
Gets information on a currently running processes.java.util.List<OSProcess>
getProcesses(java.util.Collection<java.lang.Integer> pids, boolean slowFields)
Gets information on a currently running processes.OSService[]
getServices()
Gets the all services on the system.java.util.List<OSSession>
getSessions()
Gets currently logged in users.OperatingSystemVersion
getVersion()
Operating system version.OperatingSystem.OSVersionInfo
getVersionInfo()
Operating system version information.boolean
isElevated()
Determine whether the current process has elevated permissions such as sudo / Administratorprotected java.util.List<OSProcess>
processSort(java.util.List<OSProcess> processes, int limit, OperatingSystem.ProcessSort sort)
Sorts an array of processes using the specified sorting, returning an array with the top limit results if positive.protected abstract int
queryBitness(int jvmBitness)
Backup OS-specific query to determine bitness if previous checks failprotected abstract boolean
queryElevated()
protected abstract AbstractOperatingSystem.FamilyVersionInfo
queryFamilyVersionInfo()
protected abstract java.lang.String
queryManufacturer()
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.OperatingSystem
getChildProcesses, getFileSystem, getInternetProtocolStats, getNetworkParams, getProcess, getProcessAffinityMask, getProcessCount, getProcesses, getProcessId, getSystemBootTime, getSystemUptime, getThreadCount
-
Field Details
-
OSHI_OS_UNIX_WHOCOMMAND
public static final java.lang.String OSHI_OS_UNIX_WHOCOMMAND- See Also:
- Constant Field Values
-
USE_WHO_COMMAND
protected static final boolean USE_WHO_COMMAND -
version
-
-
Constructor Details
-
AbstractOperatingSystem
public AbstractOperatingSystem()
-
-
Method Details
-
getManufacturer
public java.lang.String getManufacturer()Description copied from interface:OperatingSystem
Manufacturer.- Specified by:
getManufacturer
in interfaceOperatingSystem
- Returns:
- String.
-
queryManufacturer
protected abstract java.lang.String queryManufacturer() -
getFamily
public java.lang.String getFamily()Description copied from interface:OperatingSystem
Operating system family.- Specified by:
getFamily
in interfaceOperatingSystem
- Returns:
- String.
-
getVersionInfo
Description copied from interface:OperatingSystem
Operating system version information.- Specified by:
getVersionInfo
in interfaceOperatingSystem
- Returns:
- Version information.
-
queryFamilyVersionInfo
-
getVersion
Description copied from interface:OperatingSystem
Operating system version.- Specified by:
getVersion
in interfaceOperatingSystem
- Returns:
- Version.
-
getBitness
public int getBitness()Description copied from interface:OperatingSystem
Gets the bitness (32 or 64) of the operating system.- Specified by:
getBitness
in interfaceOperatingSystem
- Returns:
- The number of bits supported by the operating system.
-
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
-
isElevated
public boolean isElevated()Description copied from interface:OperatingSystem
Determine whether the current process has elevated permissions such as sudo / Administrator- Specified by:
isElevated
in interfaceOperatingSystem
- Returns:
- True if this process has elevated permissions
-
getServices
Description copied from interface:OperatingSystem
Gets the all services on the system. The definition of what is a service is platform-dependent.- Specified by:
getServices
in interfaceOperatingSystem
- Returns:
- An array of
OSService
objects
-
queryElevated
protected abstract boolean queryElevated() -
getSessions
Description copied from interface:OperatingSystem
Gets currently logged in users.On macOS, Linux, and Unix systems, the default implementation uses native code (see
man getutxent
) that is not thread safe. OSHI's use of this code is synchronized and may be used in a multi-threaded environment without introducing any additional conflicts. Users should note, however, that other operating system code may access the same native code.The
Who.queryWho()
method produces similar output parsing the output of the Posix-standardwho
command, and may internally employ reentrant code on some platforms. Users may opt to use this command-line variant by default using theoshi.os.unix.whoCommand
configuration property.- Specified by:
getSessions
in interfaceOperatingSystem
- Returns:
- An
UnmodifiableList
ofOSSession
objects representing logged-in users
-
processSort
protected java.util.List<OSProcess> processSort(java.util.List<OSProcess> processes, int limit, OperatingSystem.ProcessSort sort)Sorts an array of processes using the specified sorting, returning an array with the top limit results if positive.- Parameters:
processes
- The array to sortlimit
- The number of results to return if positive; if zero returns all resultssort
- The sorting to use, or null- Returns:
- An array of size limit (if positive) or of all processes, sorted as specified
-
getProcesses
Description copied from interface:OperatingSystem
Gets currently running processes. No order is guaranteed.- Specified by:
getProcesses
in interfaceOperatingSystem
- Returns:
- An array of
OSProcess
objects for the specified number (or all) of currently running processes, sorted as specified. The array may contain null elements if a process terminates during iteration. Some fields that are slow to retrieve (e.g., commandlines and group information on Windows, open files on Unix and Linux) will be skipped.
-
getProcesses
Description copied from interface:OperatingSystem
Gets currently running processes, optionally limited to the top "N" for a particular sorting order. If a positive limit is specified, returns only that number of processes; zero will return all processes. The order may be specified by the sort parameter, for example, to return the top cpu or memory consuming processes; if null, no order is guaranteed.- Specified by:
getProcesses
in interfaceOperatingSystem
- Parameters:
limit
- Max number of results to return, or 0 to return all resultssort
- If not null, determines sorting of results- Returns:
- An array of
OSProcess
objects for the specified number (or all) of currently running processes, sorted as specified. The array may contain null elements if a process terminates during iteration. Some fields that are slow to retrieve (e.g., group information on Windows, open files on Unix and Linux) will be skipped.
-
getProcesses
Description copied from interface:OperatingSystem
Gets information on a currently running processes. This has improved performance on Windows based operating systems vs. iterating individual processes. By default, includes all process information.- Specified by:
getProcesses
in interfaceOperatingSystem
- Parameters:
pids
- A collection of process IDs- Returns:
- An
OSProcess
object for the specified process ids if it is running
-
getProcesses
public java.util.List<OSProcess> getProcesses(java.util.Collection<java.lang.Integer> pids, boolean slowFields)Description copied from interface:OperatingSystem
Gets information on a currently running processes. This has improved performance on Windows based operating systems vs. iterating individual processes.- Specified by:
getProcesses
in interfaceOperatingSystem
- Parameters:
pids
- A collection of process IDsslowFields
- If false, skipOSProcess
fields that are slow to retrieve (e.g., group information on Windows, open files on Unix and Linux). If true, include all fields, regardless of how long it takes to retrieve the data.- Returns:
- An
OSProcess
object for the specified process ids if it is running
-
getProcess
Description copied from interface:OperatingSystem
Gets information on a currently running process- Specified by:
getProcess
in interfaceOperatingSystem
- Parameters:
pid
- A process ID- Returns:
- An
OSProcess
object for the specified process id if it is running; null otherwise
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-