Class BsdOperatingSystem

java.lang.Object
oshi.software.common.AbstractOperatingSystem
oshi.software.common.os.unix.bsd.BsdOperatingSystem
All Implemented Interfaces:
OperatingSystem
Direct Known Subclasses:
DragonFlyBsdOperatingSystem, FreeBsdOperatingSystem, NetBsdOperatingSystem, OpenBsdOperatingSystem

@ThreadSafe public abstract class BsdOperatingSystem extends AbstractOperatingSystem
Abstract base shared by the BSD-family OperatingSystem implementations (FreeBSD, OpenBSD, DragonFly, NetBSD). Holds the cross-BSD-identical pieces: the Unix/BSD manufacturer, the uname-based bitness, the process/child/descendant queries, the ps -axo pid process count, the ps -axo nlwp thread count, the /etc/rc.d services, and the memoized system uptime/boot time. Per-platform work (the ps process enumeration, the boot-time source, the current-thread factory, and the native version/file-system/network queries) is provided by the subclasses.
  • Constructor Details

    • BsdOperatingSystem

      public BsdOperatingSystem()
  • Method Details

    • queryManufacturer

      public String queryManufacturer()
      Description copied from class: AbstractOperatingSystem
      Queries the OS manufacturer.
      Specified by:
      queryManufacturer in class AbstractOperatingSystem
      Returns:
      the manufacturer string
    • queryBitness

      protected int queryBitness(int jvmBitness)
      Description copied from class: AbstractOperatingSystem
      Backup OS-specific query to determine bitness if previous checks fail
      Specified by:
      queryBitness in class AbstractOperatingSystem
      Parameters:
      jvmBitness - The bitness of the JVM
      Returns:
      The operating system bitness
    • queryAllProcesses

      public List<OSProcess> queryAllProcesses()
      Description copied from class: AbstractOperatingSystem
      Queries all processes on the system.
      Specified by:
      queryAllProcesses in class AbstractOperatingSystem
      Returns:
      a list of all OS processes
    • queryChildProcesses

      public List<OSProcess> queryChildProcesses(int parentPid)
      Description copied from class: AbstractOperatingSystem
      Queries the children of a process.
      Specified by:
      queryChildProcesses in class AbstractOperatingSystem
      Parameters:
      parentPid - the parent process ID
      Returns:
      a list of child processes (including the parent itself)
    • queryDescendantProcesses

      public List<OSProcess> queryDescendantProcesses(int parentPid)
      Description copied from class: AbstractOperatingSystem
      Queries the descendants of a process.
      Specified by:
      queryDescendantProcesses in class AbstractOperatingSystem
      Parameters:
      parentPid - the parent process ID
      Returns:
      a list of descendant processes (including the parent itself)
    • getProcess

      public OSProcess getProcess(int pid)
      Description copied from interface: OperatingSystem
      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
    • getProcessCount

      public int getProcessCount()
      Description copied from interface: OperatingSystem
      Get the number of processes currently running
      Returns:
      The number of processes running
    • getThreadCount

      public int getThreadCount()
      Description copied from interface: OperatingSystem
      Get the number of threads currently running
      Returns:
      The number of threads running
    • getSystemUptime

      public long getSystemUptime()
      Description copied from interface: OperatingSystem
      Get the System up time (time since boot).
      Returns:
      Number of seconds since boot.
    • getSystemBootTime

      public long getSystemBootTime()
      Description copied from interface: OperatingSystem
      Get Unix time of boot.
      Returns:
      The approximate time at which the system booted, in seconds since the Unix epoch.
    • getServices

      public List<OSService> getServices()
      Description copied from interface: OperatingSystem
      Gets the all services on the system. The definition of what is a service is platform-dependent.
      Returns:
      An array of OSService objects
    • getProcessListFromPS

      protected abstract List<OSProcess> getProcessListFromPS(int pid)
      Enumerates processes (or a single process when pid >= 0) via the platform's ps command.
      Parameters:
      pid - the process ID, or -1 for all processes
      Returns:
      the process list
    • queryBootTime

      protected abstract long queryBootTime()
      Queries the system boot time in seconds since the epoch.
      Returns:
      the boot time in seconds