Interface OperatingSystem
- All Known Implementing Classes:
AbstractOperatingSystem
,AixOperatingSystem
,FreeBsdOperatingSystem
,LinuxOperatingSystem
,MacOperatingSystem
,OpenBsdOperatingSystem
,SolarisOperatingSystem
,WindowsOperatingSystem
Considered thread safe, but see remarks for the getSessions()
method.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A class representing the Operating System version details.static final class
Constants which may be used to filter Process lists ingetProcesses(Predicate, Comparator, int)
,getChildProcesses(int, Predicate, Comparator, int)
, andgetDescendantProcesses(int, Predicate, Comparator, int)
.static enum
Deprecated.static final class
Constants which may be used to sort Process lists ingetProcesses(Predicate, Comparator, int)
,getChildProcesses(int, Predicate, Comparator, int)
, andgetDescendantProcesses(int, Predicate, Comparator, int)
. -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the bitness (32 or 64) of the operating system.getChildProcesses
(int parentPid, int limit, OperatingSystem.ProcessSort sort) Deprecated.UsegetChildProcesses(int, Predicate, Comparator, int)
with sorting constants fromOperatingSystem.ProcessSorting
.getChildProcesses
(int parentPid, Predicate<OSProcess> filter, Comparator<OSProcess> sort, int limit) Gets currently running child processes of provided parent PID, optionally filtering, sorting, and limited to the top "N".getDescendantProcesses
(int parentPid, Predicate<OSProcess> filter, 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".default List<OSDesktopWindow>
getDesktopWindows
(boolean visibleOnly) Gets windows on the operating system's GUI desktop.Get the Operating System family.Instantiates aFileSystem
object.Instantiates aInternetProtocolStats
object.Get the Operating System manufacturer.Instantiates aNetworkParams
object.getProcess
(int pid) Gets information on a currently running processint
Get the number of processes currently runningGets currently running processes.getProcesses
(int limit, OperatingSystem.ProcessSort sort) Deprecated.UsegetProcesses(Predicate, Comparator, int)
with sorting constants fromOperatingSystem.ProcessSorting
.getProcesses
(Collection<Integer> pids) Gets information on aCollection
of currently running processes.getProcesses
(Predicate<OSProcess> filter, Comparator<OSProcess> sort, int limit) Gets currently running processes, optionally filtering, sorting, and limited to the top "N".int
Gets the current process IDdefault OSService[]
Gets the all services on the system.Gets currently logged in users.long
Get Unix time of boot.long
Get the System up time (time since boot).int
Get the number of threads currently runningGet Operating System version information.default boolean
Determine whether the current process has elevated permissions such as sudo / Administrator
-
Method Details
-
getFamily
String getFamily()Get the Operating System family.- Returns:
- the family
-
getManufacturer
String getManufacturer()Get the Operating System manufacturer.- Returns:
- the manufacturer
-
getVersionInfo
OperatingSystem.OSVersionInfo getVersionInfo()Get Operating System version information.- Returns:
- version information
-
getFileSystem
FileSystem getFileSystem()Instantiates aFileSystem
object.- Returns:
- A
FileSystem
object.
-
getInternetProtocolStats
InternetProtocolStats getInternetProtocolStats()Instantiates aInternetProtocolStats
object.- Returns:
- a
InternetProtocolStats
object.
-
getProcesses
Gets currently running processes. No order is guaranteed.- Returns:
- A list of
OSProcess
objects for the specified number (or all) of currently running processes, sorted as specified. The list may contain null elements or processes with a state ofOSProcess.State.INVALID
if a process terminates during iteration.
-
getProcesses
Gets currently running processes, optionally filtering, sorting, and limited to the top "N".- Parameters:
filter
- An optionalPredicate
limiting the results to the specified filter. Some common predicates are available inOperatingSystem.ProcessSorting
. May benull
for no filtering.sort
- An optionalComparator
specifying the sorting order. Some common comparators are available inOperatingSystem.ProcessSorting
. May benull
for no sorting.limit
- Max number of results to return, or 0 to return all results- Returns:
- A list of
OSProcess
objects, optionally filtered, sorted, and limited to the specified number.The list may contain processes with a state of
OSProcess.State.INVALID
if a process terminates during iteration.
-
getProcesses
Deprecated.UsegetProcesses(Predicate, Comparator, int)
with sorting constants fromOperatingSystem.ProcessSorting
.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 the sort isnull
, 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:
- A list of
OSProcess
objects for the specified number (or all) of currently running processes, sorted as specified. The list may contain null elements or processes with a state ofOSProcess.State.INVALID
if a process terminates during iteration.
-
getProcesses
Gets information on aCollection
of currently running processes. This has potentially improved performance vs. iterating individual processes.- Parameters:
pids
- A collection of process IDs- Returns:
- A list of
OSProcess
objects for the specified process ids if it is running
-
getProcess
Gets information on a currently running process- Parameters:
pid
- A process ID- Returns:
- An
OSProcess
object for the specified process id if it is running; null otherwise
-
getChildProcesses
@Deprecated default List<OSProcess> getChildProcesses(int parentPid, int limit, OperatingSystem.ProcessSort sort) Deprecated.UsegetChildProcesses(int, Predicate, Comparator, int)
with sorting constants fromOperatingSystem.ProcessSorting
.Gets currently running child processes of provided parent PID, 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 the sort isnull
, 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:
- A list of
OSProcess
objects representing the specified number (or all) of currently running child processes of the provided PID, sorted as specified. The list may contain null elements or processes with a state ofOSProcess.State.INVALID
if a process terminates during iteration.
-
getChildProcesses
List<OSProcess> getChildProcesses(int parentPid, Predicate<OSProcess> filter, Comparator<OSProcess> sort, int limit) Gets currently running child processes of provided parent PID, optionally filtering, sorting, and limited to the top "N".- Parameters:
parentPid
- The Process ID whose children to list.filter
- An optionalPredicate
limiting the results to the specified filter. Some common predicates are available inOperatingSystem.ProcessSorting
. May benull
for no filtering.sort
- An optionalComparator
specifying the sorting order. Some common comparators are available inOperatingSystem.ProcessSorting
. May benull
for no sorting.limit
- Max number of results to return, or 0 to return all results- Returns:
- A list of
OSProcess
objects 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.INVALID
if a process terminates during iteration.
-
getDescendantProcesses
List<OSProcess> getDescendantProcesses(int parentPid, Predicate<OSProcess> filter, 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".- Parameters:
parentPid
- The Process ID whose children to list.filter
- An optionalPredicate
limiting the results to the specified filter. Some common predicates are available inOperatingSystem.ProcessSorting
. May benull
for no filtering.sort
- An optionalComparator
specifying the sorting order. Some common comparators are available inOperatingSystem.ProcessSorting
. May benull
for no sorting.limit
- Max number of results to return, or 0 to return all results- Returns:
- A list of
OSProcess
objects 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.INVALID
if a process terminates during iteration.
-
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
default 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 aNetworkParams
object.- Returns:
- A
NetworkParams
object.
-
getServices
Gets the all services on the system. The definition of what is a service is platform-dependent.- Returns:
- An array of
OSService
objects
-
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-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.- Returns:
- A list of
OSSession
objects representing logged-in users
-
getDesktopWindows
Gets windows on the operating system's GUI desktop.On Unix-like systems, reports X11 windows only, which may be limited to the current display and will not report windows used by other window managers.
While not a guarantee, a best effort is made to return windows in foreground-to-background order. This ordering may be used along with
OSDesktopWindow.getOrder()
to (probably) determine the frontmost window.- Parameters:
visibleOnly
- Whether to restrict the list to only windows visible to the user.This is a best effort attempt at a reasonable definition of visibility. Visible windows may be completely transparent.
- Returns:
- A list of
OSDesktopWindow
objects representing the desktop windows.
-
OperatingSystem.ProcessSorting
.