Interface OperatingSystem

All Known Implementing Classes:
AbstractOperatingSystem, FreeBsdOperatingSystem, LinuxOperatingSystem, MacOperatingSystem, SolarisOperatingSystem, WindowsOperatingSystem

@ThreadSafe
public interface OperatingSystem
An operating system (OS) is the software on a computer that manages the way different programs use its hardware, and regulates the ways that a user controls the computer.

Considered thread safe, but see remarks for the getSessions() method.

  • Method Details

    • getFamily

      java.lang.String getFamily()
      Operating system family.
      Returns:
      String.
    • getManufacturer

      java.lang.String getManufacturer()
      Manufacturer.
      Returns:
      String.
    • getVersion

      @Deprecated OperatingSystemVersion getVersion()
      Deprecated.
      Operating system version.
      Returns:
      Version.
    • getVersionInfo

      Operating system version information.
      Returns:
      Version information.
    • getFileSystem

      FileSystem getFileSystem()
      Instantiates a FileSystem object.
      Returns:
      A FileSystem object.
    • getInternetProtocolStats

      InternetProtocolStats getInternetProtocolStats()
      Instantiates a InternetProtocolStats object.
      Returns:
      a InternetProtocolStats object.
    • 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-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.

      Returns:
      An UnmodifiableList of OSSession objects representing logged-in users
    • getProcesses

      OSProcess[] getProcesses()
      Gets currently running processes. No order is guaranteed.
      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

      OSProcess[] getProcesses​(int limit, OperatingSystem.ProcessSort sort)
      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 results
      sort - 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

      OSProcess[] getProcesses​(int limit, OperatingSystem.ProcessSort sort, boolean slowFields)
      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 results
      sort - If not null, determines sorting of results
      slowFields - If false, skip OSProcess 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 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.
    • getProcesses

      java.util.List<OSProcess> getProcesses​(java.util.Collection<java.lang.Integer> pids)
      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 OSProcess object 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 IDs
      slowFields - If false, skip OSProcess 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

      OSProcess getProcess​(int pid)
      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
    • getProcess

      OSProcess getProcess​(int pid, boolean slowFields)
      Gets information on a currently running process
      Parameters:
      pid - A process ID
      slowFields - If false, skip OSProcess 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 id if it is running; null otherwise
    • getChildProcesses

      OSProcess[] getChildProcesses​(int parentPid, int limit, OperatingSystem.ProcessSort sort)
      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 ID
      limit - Max number of results to return, or 0 to return all results
      sort - If not null, determines sorting of results
      Returns:
      An array of OSProcess objects 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 a NetworkParams object.
      Returns:
      A NetworkParams object.
    • getServices

      OSService[] getServices()
      Gets the all services on the system. The definition of what is a service is platform-dependent.
      Returns:
      An array of OSService objects