- All Known Implementing Classes:
- AbstractOperatingSystem,- AixOperatingSystem,- FreeBsdOperatingSystem,- LinuxOperatingSystem,- MacOperatingSystem,- OpenBsdOperatingSystem,- SolarisOperatingSystem,- WindowsOperatingSystem
 Considered thread safe, but see remarks for the getSessions() method.
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic classA class representing the Operating System version details.static final classConstants which may be used to filter Process lists ingetProcesses(Predicate, Comparator, int),getChildProcesses(int, Predicate, Comparator, int), andgetDescendantProcesses(int, Predicate, Comparator, int).static final classConstants which may be used to sort Process lists ingetProcesses(Predicate, Comparator, int),getChildProcesses(int, Predicate, Comparator, int), andgetDescendantProcesses(int, Predicate, Comparator, int).
- 
Method SummaryModifier and TypeMethodDescriptionintGets the bitness (32 or 64) of the operating system.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".default OSProcessGets the current process.Makes a best effort to get the current thread.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 aFileSystemobject.default List<ApplicationInfo> Retrieves a list of installed applications on the system.Instantiates aInternetProtocolStatsobject.Get the Operating System manufacturer.Instantiates aNetworkParamsobject.getProcess(int pid) Gets information on a currently running processintGet the number of processes currently runningGets currently running processes.getProcesses(Collection<Integer> pids) Gets information on aCollectionof 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".intGets the current process ID (PID).Gets the all services on the system.Gets currently logged in users.longGet Unix time of boot.longGet the System up time (time since boot).intGet the number of threads currently runningintMakes a best effort to get the current thread ID (TID).Get Operating System version information.default booleanDetermine whether the current process has elevated permissions such as sudo / Administrator
- 
Method Details- 
getFamilyString getFamily()Get the Operating System family.- Returns:
- the family
 
- 
getManufacturerString getManufacturer()Get the Operating System manufacturer.- Returns:
- the manufacturer
 
- 
getVersionInfoOperatingSystem.OSVersionInfo getVersionInfo()Get Operating System version information.- Returns:
- version information
 
- 
getFileSystemFileSystem getFileSystem()Instantiates aFileSystemobject.- Returns:
- A FileSystemobject.
 
- 
getInternetProtocolStatsInternetProtocolStats getInternetProtocolStats()Instantiates aInternetProtocolStatsobject.- Returns:
- a InternetProtocolStatsobject.
 
- 
getProcessesGets currently running processes. No order is guaranteed.- Returns:
- A list of OSProcessobjects 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.INVALIDif a process terminates during iteration.
 
- 
getProcessesGets currently running processes, optionally filtering, sorting, and limited to the top "N".- Parameters:
- filter- An optional- Predicatelimiting the results to the specified filter. Some common predicates are available in- OperatingSystem.ProcessSorting. May be- nullfor no filtering.
- sort- An optional- Comparatorspecifying the sorting order. Some common comparators are available in- OperatingSystem.ProcessSorting. May be- nullfor 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.
 
- 
getProcessesGets information on aCollectionof currently running processes. This has potentially improved performance vs. iterating individual processes.- Parameters:
- pids- A collection of process IDs
- Returns:
- A list of OSProcessobjects for the specified process ids if it is running
 
- 
getProcessGets 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
 
- 
getChildProcessesList<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 optional- Predicatelimiting the results to the specified filter. Some common predicates are available in- OperatingSystem.ProcessSorting. May be- nullfor no filtering.
- sort- An optional- Comparatorspecifying the sorting order. Some common comparators are available in- OperatingSystem.ProcessSorting. May be- nullfor 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.
 
- 
getDescendantProcessesList<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 optional- Predicatelimiting the results to the specified filter. Some common predicates are available in- OperatingSystem.ProcessSorting. May be- nullfor no filtering.
- sort- An optional- Comparatorspecifying the sorting order. Some common comparators are available in- OperatingSystem.ProcessSorting. May be- nullfor 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.
 
- 
getProcessIdint getProcessId()Gets the current process ID (PID).- Returns:
- the Process ID of the current process
 
- 
getCurrentProcessGets the current process.- Returns:
- the current process
 
- 
getProcessCountint getProcessCount()Get the number of processes currently running- Returns:
- The number of processes running
 
- 
getThreadIdint getThreadId()Makes a best effort to get the current thread ID (TID). May not be useful in a multithreaded environment. The thread ID returned may have been short lived and no longer exist.Thread IDs on macOS are not correlated with any other Operating System output. - Returns:
- the Thread ID of the current thread if known, 0 otherwise.
 
- 
getCurrentThreadOSThread getCurrentThread()Makes a best effort to get the current thread. May not be useful in a multithreaded environment. The thread returned may have been short lived and no longer exist.On macOS, returns the oldest thread in the calling process. - Returns:
- the current thread if known; an invalid thread otherwise.
 
- 
getThreadCountint getThreadCount()Get the number of threads currently running- Returns:
- The number of threads running
 
- 
getBitnessint getBitness()Gets the bitness (32 or 64) of the operating system.- Returns:
- The number of bits supported by the operating system.
 
- 
getSystemUptimelong getSystemUptime()Get the System up time (time since boot).- Returns:
- Number of seconds since boot.
 
- 
getSystemBootTimelong getSystemBootTime()Get Unix time of boot.- Returns:
- The approximate time at which the system booted, in seconds since the Unix epoch.
 
- 
isElevateddefault boolean isElevated()Determine whether the current process has elevated permissions such as sudo / Administrator- Returns:
- True if this process has elevated permissions
 
- 
getNetworkParamsNetworkParams getNetworkParams()Instantiates aNetworkParamsobject.- Returns:
- A NetworkParamsobject.
 
- 
getServicesGets the all services on the system. The definition of what is a service is platform-dependent.- Returns:
- An array of OSServiceobjects
 
- 
getSessionsGets 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:
- A list of OSSessionobjects representing logged-in users
 
- 
getDesktopWindowsGets 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 OSDesktopWindowobjects representing the desktop windows.
 
- 
getInstalledApplicationsRetrieves a list of installed applications on the system.This method is implemented per OS. If the OS does not support this feature, it returns an empty list. - Returns:
- A list of installed applications or an empty list if unsupported.
 
 
-