JNA-based operating system and hardware information library for Java providing cross-platform access to system metrics
—
Operating system details, process management, file system access, and network configuration with comprehensive process monitoring capabilities.
Interface providing access to operating system information, processes, file systems, and network configuration.
interface OperatingSystem {
String getFamily();
String getManufacturer();
OSVersionInfo getVersionInfo();
FileSystem getFileSystem();
InternetProtocolStats getInternetProtocolStats();
List<OSProcess> getProcesses();
List<OSProcess> getProcesses(Predicate<OSProcess> filter, Comparator<OSProcess> sort, int limit);
List<OSProcess> getProcesses(Collection<Integer> pids);
OSProcess getProcess(int pid);
List<OSProcess> getChildProcesses(int parentPid, Predicate<OSProcess> filter, Comparator<OSProcess> sort, int limit);
List<OSProcess> getDescendantProcesses(int parentPid, Predicate<OSProcess> filter, Comparator<OSProcess> sort, int limit);
int getProcessId();
OSProcess getCurrentProcess();
int getProcessCount();
int getThreadId();
OSThread getCurrentThread();
int getThreadCount();
int getBitness();
long getSystemUptime();
long getSystemBootTime();
boolean isElevated();
NetworkParams getNetworkParams();
List<OSService> getServices();
List<OSSession> getSessions();
List<OSDesktopWindow> getDesktopWindows(boolean visibleOnly);
List<ApplicationInfo> getInstalledApplications();
}Operating system version details.
class OSVersionInfo {
String getVersion();
String getCodeName();
String getBuildNumber();
String toString();
}Information about running processes including CPU usage, memory consumption, and process relationships.
interface OSProcess {
String getName();
String getPath();
String getCommandLine();
String getCurrentWorkingDirectory();
String getUser();
String getUserID();
String getGroup();
String getGroupID();
State getState();
int getProcessID();
int getParentProcessID();
int getThreadCount();
int getPriority();
long getVirtualSize();
long getResidentSetSize();
long getKernelTime();
long getUserTime();
long getUpTime();
long getStartTime();
long getBytesRead();
long getBytesWritten();
long getOpenFiles();
int getBitness();
long getAffinityMask();
double getProcessCpuLoadCumulative();
double getProcessCpuLoadBetweenTicks(OSProcess priorSnapshot);
String[] getArguments();
Map<String, String> getEnvironmentVariables();
List<OSThread> getThreadDetails();
int getMinorFaults();
int getMajorFaults();
long getContextSwitches();
enum State {
NEW, RUNNING, SLEEPING, WAITING, ZOMBIE, STOPPED, OTHER, INVALID
}
}Utility classes for filtering and sorting process lists.
class ProcessFiltering {
static final Predicate<OSProcess> ALL_PROCESSES;
static final Predicate<OSProcess> VALID_PROCESS;
static final Predicate<OSProcess> NO_PARENT;
static final Predicate<OSProcess> BITNESS_64;
static final Predicate<OSProcess> BITNESS_32;
}
class ProcessSorting {
static final Comparator<OSProcess> NO_SORTING;
static final Comparator<OSProcess> CPU_DESC;
static final Comparator<OSProcess> RSS_DESC;
static final Comparator<OSProcess> UPTIME_ASC;
static final Comparator<OSProcess> UPTIME_DESC;
static final Comparator<OSProcess> PID_ASC;
static final Comparator<OSProcess> PARENTPID_ASC;
static final Comparator<OSProcess> NAME_ASC;
}Information about threads within processes.
interface OSThread {
String getName();
int getThreadId();
OSProcess.State getState();
long getStartTime();
long getStartMemoryAddress();
long getContextSwitches();
long getKernelTime();
long getUserTime();
long getUpTime();
int getPriority();
}Network configuration information.
interface NetworkParams {
String getHostName();
String getDomainName();
String[] getDnsServers();
String getIpv4DefaultGateway();
String getIpv6DefaultGateway();
}Network protocol statistics and connection information.
interface InternetProtocolStats {
TcpStats getTCPv4Stats();
TcpStats getTCPv6Stats();
UdpStats getUDPv4Stats();
UdpStats getUDPv6Stats();
List<IPConnection> getConnections();
class TcpStats {
long getConnectionsEstablished();
long getConnectionsActive();
long getConnectionsPassive();
long getConnectionFailures();
long getConnectionsReset();
long getSegmentsSent();
long getSegmentsReceived();
long getSegmentsRetransmitted();
long getInErrors();
long getOutRsts();
}
class UdpStats {
long getDatagramsSent();
long getDatagramsReceived();
long getDatagramsNoPort();
long getDatagramsReceivedErrors();
}
class IPConnection {
String getType();
String getLocalAddress();
int getLocalPort();
String getForeignAddress();
int getForeignPort();
TcpState getState();
int getOwningProcessId();
enum TcpState {
CLOSED, LISTEN, SYN_SENT, SYN_RECV, ESTABLISHED, FIN_WAIT_1,
FIN_WAIT_2, CLOSE_WAIT, CLOSING, LAST_ACK, TIME_WAIT, DELETE_TCB,
NONE, UNKNOWN
}
}
}Operating system service information.
interface OSService {
String getName();
int getProcessID();
State getState();
enum State {
RUNNING, STOPPED, START_PENDING, STOP_PENDING, CONTINUE_PENDING, PAUSE_PENDING, PAUSED
}
}Information about logged-in users.
interface OSSession {
String getUserName();
String getTerminalDevice();
long getLoginTime();
String getHost();
}Desktop window information for GUI applications.
interface OSDesktopWindow {
long getWindowId();
String getTitle();
String getCommand();
Rectangle getLocAndSize();
int getOwningProcessId();
long getOrder();
boolean isVisible();
}Information about installed applications on the system.
interface ApplicationInfo {
String getName();
String getVersion();
String getInstallDate();
}import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
System.out.println("OS Family: " + os.getFamily());
System.out.println("Manufacturer: " + os.getManufacturer());
System.out.println("Version: " + os.getVersionInfo());
System.out.println("Bitness: " + os.getBitness() + "-bit");
System.out.println("Process Count: " + os.getProcessCount());
System.out.println("Thread Count: " + os.getThreadCount());
System.out.println("Uptime: " + os.getSystemUptime() + " seconds");import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;
import oshi.software.os.OSProcess;
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
// Get all processes
List<OSProcess> processes = os.getProcesses();
// Get top 10 processes by CPU usage
List<OSProcess> topCpuProcesses = os.getProcesses(
OperatingSystem.ProcessFiltering.VALID_PROCESS,
OperatingSystem.ProcessSorting.CPU_DESC,
10
);
for (OSProcess process : topCpuProcesses) {
System.out.printf("PID: %d, Name: %s, CPU: %.1f%%, Memory: %d MB%n",
process.getProcessID(),
process.getName(),
process.getProcessCpuLoadCumulative() * 100,
process.getResidentSetSize() / 1024 / 1024
);
}import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;
import oshi.software.os.OSProcess;
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
// Get 64-bit processes only, sorted by memory usage
List<OSProcess> processes64bit = os.getProcesses(
OperatingSystem.ProcessFiltering.BITNESS_64,
OperatingSystem.ProcessSorting.RSS_DESC,
20
);
// Get child processes of a specific PID
List<OSProcess> children = os.getChildProcesses(
1234, // parent PID
OperatingSystem.ProcessFiltering.VALID_PROCESS,
OperatingSystem.ProcessSorting.NAME_ASC,
0 // no limit
);import oshi.SystemInfo;
import oshi.software.os.NetworkParams;
SystemInfo si = new SystemInfo();
NetworkParams netParams = si.getOperatingSystem().getNetworkParams();
System.out.println("Hostname: " + netParams.getHostName());
System.out.println("Domain: " + netParams.getDomainName());
System.out.println("IPv4 Gateway: " + netParams.getIpv4DefaultGateway());
System.out.println("IPv6 Gateway: " + netParams.getIpv6DefaultGateway());
String[] dnsServers = netParams.getDnsServers();
System.out.println("DNS Servers: " + Arrays.toString(dnsServers));import oshi.SystemInfo;
import oshi.software.os.OSSession;
SystemInfo si = new SystemInfo();
List<OSSession> sessions = si.getOperatingSystem().getSessions();
for (OSSession session : sessions) {
System.out.printf("User: %s, Terminal: %s, Host: %s, Login Time: %s%n",
session.getUserName(),
session.getTerminalDevice(),
session.getHost(),
new Date(session.getLoginTime() * 1000)
);
}import oshi.SystemInfo;
import oshi.software.os.OperatingSystem;
import oshi.software.os.OSProcess;
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
// Get current process info
int currentPid = os.getProcessId();
OSProcess currentProcess = os.getCurrentProcess();
System.out.println("Current PID: " + currentPid);
System.out.println("Process Name: " + currentProcess.getName());
System.out.println("Command Line: " + currentProcess.getCommandLine());
System.out.println("Working Directory: " + currentProcess.getCurrentWorkingDirectory());
System.out.println("User: " + currentProcess.getUser());Install with Tessl CLI
npx tessl i tessl/maven-com-github-oshi--oshi-core