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
  • 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
  • Constructor Details

    • AbstractOperatingSystem

      public AbstractOperatingSystem()
  • Method Details

    • getManufacturer

      public java.lang.String getManufacturer()
      Description copied from interface: OperatingSystem
      Manufacturer.
      Specified by:
      getManufacturer in interface OperatingSystem
      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 interface OperatingSystem
      Returns:
      String.
    • getVersionInfo

      public OperatingSystem.OSVersionInfo getVersionInfo()
      Description copied from interface: OperatingSystem
      Operating system version information.
      Specified by:
      getVersionInfo in interface OperatingSystem
      Returns:
      Version information.
    • queryFamilyVersionInfo

      protected abstract AbstractOperatingSystem.FamilyVersionInfo queryFamilyVersionInfo()
    • getBitness

      public int getBitness()
      Description copied from interface: OperatingSystem
      Gets the bitness (32 or 64) of the operating system.
      Specified by:
      getBitness in interface OperatingSystem
      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 interface OperatingSystem
      Returns:
      True if this process has elevated permissions
    • getServices

      public OSService[] 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 interface OperatingSystem
      Returns:
      An array of OSService objects
    • queryElevated

      protected abstract boolean queryElevated()
    • 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 sort
      limit - The number of results to return if positive; if zero returns all results
      sort - The sorting to use, or null
      Returns:
      An array of size limit (if positive) or of all processes, sorted as specified
    • getSessions

      public java.util.List<OSSession> 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-standard who command, and may internally employ reentrant code on some platforms. Users may opt to use this command-line variant by default using the oshi.os.unix.whoCommand configuration property.

      Specified by:
      getSessions in interface OperatingSystem
      Returns:
      A list of OSSession objects representing logged-in users
    • getProcesses

      public java.util.List<OSProcess> getProcesses()
      Description copied from interface: OperatingSystem
      Gets currently running processes. No order is guaranteed.
      Specified by:
      getProcesses in interface OperatingSystem
      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 of OSProcess.State.INVALID if a process terminates during iteration.
    • getProcesses

      public java.util.List<OSProcess> getProcesses​(java.util.Collection<java.lang.Integer> pids)
      Description copied from interface: OperatingSystem
      Gets information on a Collection of currently running processes. This has potentially improved performance vs. iterating individual processes.
      Specified by:
      getProcesses in interface OperatingSystem
      Parameters:
      pids - A collection of process IDs
      Returns:
      A list of OSProcess objects for the specified process ids if it is running
    • getChildProcesses

      public java.util.List<OSProcess> getChildProcesses​(int parentPid, int limit, OperatingSystem.ProcessSort sort)
      Description copied from interface: OperatingSystem
      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 is null, no order is guaranteed.
      Specified by:
      getChildProcesses in interface OperatingSystem
      Parameters:
      parentPid - A process ID
      limit - Max number of results to return, or 0 to return all results
      sort - 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 of OSProcess.State.INVALID if a process terminates during iteration.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getDesktopWindows

      public java.util.List<OSDesktopWindow> getDesktopWindows​(boolean visibleOnly)
      Description copied from interface: OperatingSystem
      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.

      Specified by:
      getDesktopWindows in interface OperatingSystem
      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.