Interface OperatingSystem
- All Known Implementing Classes:
AbstractOperatingSystem,FreeBsdOperatingSystem,LinuxOperatingSystem,MacOperatingSystem,SolarisOperatingSystem,WindowsOperatingSystem
@ThreadSafe public interface OperatingSystem
Considered thread safe, but see remarks for the getSessions()
method.
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classOperatingSystem.OSVersionInfostatic classOperatingSystem.ProcessSortControls sorting of Process output -
Method Summary
Modifier and Type Method Description intgetBitness()Gets the bitness (32 or 64) of the operating system.OSProcess[]getChildProcesses(int parentPid, int limit, OperatingSystem.ProcessSort sort)Gets currently running child processes of provided PID.java.lang.StringgetFamily()Operating system family.FileSystemgetFileSystem()Instantiates aFileSystemobject.InternetProtocolStatsgetInternetProtocolStats()Instantiates aInternetProtocolStatsobject.java.lang.StringgetManufacturer()Manufacturer.NetworkParamsgetNetworkParams()Instantiates aNetworkParamsobject.OSProcessgetProcess(int pid)Gets information on a currently running processOSProcessgetProcess(int pid, boolean slowFields)Gets information on a currently running processlonggetProcessAffinityMask(int processId)Retrieves the process affinity mask for the specified process.intgetProcessCount()Get the number of processes currently runningOSProcess[]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.OSProcess[]getProcesses(int limit, OperatingSystem.ProcessSort sort, boolean slowFields)Gets currently running processes.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.intgetProcessId()Gets the current process IDOSService[]getServices()Gets the all services on the system.java.util.List<OSSession>getSessions()Gets currently logged in users.longgetSystemBootTime()Get Unix time of boot.longgetSystemUptime()Get the System up time (time since boot).intgetThreadCount()Get the number of threads currently runningOperatingSystemVersiongetVersion()Deprecated.UsegetVersionInfo()OperatingSystem.OSVersionInfogetVersionInfo()Operating system version information.booleanisElevated()Determine whether the current process has elevated permissions such as sudo / Administrator
-
Method Details
-
getFamily
java.lang.String getFamily()Operating system family.- Returns:
- String.
-
getManufacturer
java.lang.String getManufacturer()Manufacturer.- Returns:
- String.
-
getVersion
Deprecated.UsegetVersionInfo()Operating system version.- Returns:
- Version.
-
getVersionInfo
OperatingSystem.OSVersionInfo getVersionInfo()Operating system version information.- Returns:
- Version information.
-
getFileSystem
FileSystem getFileSystem()Instantiates aFileSystemobject.- Returns:
- A
FileSystemobject.
-
getInternetProtocolStats
InternetProtocolStats getInternetProtocolStats()Instantiates aInternetProtocolStatsobject.- Returns:
- a
InternetProtocolStatsobject.
-
getSessions
java.util.List<OSSession> getSessions()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-standardwhocommand, and may internally employ reentrant code on some platforms. Users may opt to use this command-line variant by default using theoshi.os.unix.whoCommandconfiguration property.- Returns:
- An
UnmodifiableListofOSSessionobjects representing logged-in users
-
getProcesses
OSProcess[] getProcesses()Gets currently running processes. No order is guaranteed.- Returns:
- An array of
OSProcessobjects 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
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.- 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
OSProcessobjects 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
Gets currently running processes. 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.- Parameters:
limit- Max number of results to return, or 0 to return all resultssort- If not null, determines sorting of resultsslowFields- If false, skipOSProcessfields 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 array of
OSProcessobjects 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.
-
getProcesses
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.- Parameters:
pids- A collection of process IDs- Returns:
- An
OSProcessobject for the specified process ids if it is running
-
getProcesses
java.util.List<OSProcess> getProcesses(java.util.Collection<java.lang.Integer> pids, boolean slowFields)Gets information on a currently running processes. This has improved performance on Windows based operating systems vs. iterating individual processes.- Parameters:
pids- A collection of process IDsslowFields- If false, skipOSProcessfields 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
OSProcessobject for the specified process ids if it is running
-
getProcess
Gets information on a currently running process- Parameters:
pid- A process ID- Returns:
- An
OSProcessobject for the specified process id if it is running; null otherwise
-
getProcess
Gets information on a currently running process- Parameters:
pid- A process IDslowFields- If false, skipOSProcessfields 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
OSProcessobject for the specified process id if it is running; null otherwise
-
getChildProcesses
Gets currently running child processes of provided PID. 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.- Parameters:
parentPid- A process IDlimit- Max number of results to return, or 0 to return all resultssort- If not null, determines sorting of results- Returns:
- An array of
OSProcessobjects presenting the specified number (or all) of currently running child processes of the provided PID, sorted as specified. The array may contain null elements if a process terminates during iteration.
-
getProcessAffinityMask
long getProcessAffinityMask(int processId)Retrieves the process affinity mask for the specified process.On Windows systems with more than 64 processors, if the threads of the calling process are in a single processor group, returns the process affinity mask for that group (which may be zero if the specified process is running in a different group). If the calling process contains threads in multiple groups, returns zero.
If the Operating System fails to retrieve an affinity mask (e.g., the process has terminated), returns zero.
- Parameters:
processId- The process ID for which to retrieve the affinity.- Returns:
- a bit vector in which each bit represents the processors that a process is allowed to run on.
-
getProcessId
int getProcessId()Gets the current process ID- Returns:
- the Process ID of the current process
-
getProcessCount
int getProcessCount()Get the number of processes currently running- Returns:
- The number of processes running
-
getThreadCount
int getThreadCount()Get the number of threads currently running- Returns:
- The number of threads running
-
getBitness
int getBitness()Gets the bitness (32 or 64) of the operating system.- Returns:
- The number of bits supported by the operating system.
-
getSystemUptime
long getSystemUptime()Get the System up time (time since boot).- Returns:
- Number of seconds since boot.
-
getSystemBootTime
long getSystemBootTime()Get Unix time of boot.- Returns:
- The approximate time at which the system booted, in seconds since the Unix epoch.
-
isElevated
boolean isElevated()Determine whether the current process has elevated permissions such as sudo / Administrator- Returns:
- True if this process has elevated permissions
-
getNetworkParams
NetworkParams getNetworkParams()Instantiates aNetworkParamsobject.- Returns:
- A
NetworkParamsobject.
-
getServices
OSService[] getServices()Gets the all services on the system. The definition of what is a service is platform-dependent.- Returns:
- An array of
OSServiceobjects
-