License
BSD-3-Clause
Advanced Process Querying
This module provides powerful filtering and search capabilities for processes, including a fluent query API and process tree construction.
Features:
Platform Availability:
A fluent query builder for filtering and searching processes.
This struct provides a chainable API for building complex process queries. Multiple filters can be combined to find specific processes.
Example:
auto procs = ProcessQuery()
.name("python*")
.memoryAbove(1024 * 1024 * 1024) // 1 GB
.cpuAbove(50.0)
.execute();private string namePattern_private string exePattern_private string username_private double cpuAbove_private ulong memoryAbove_private ProcessStatus status_private bool hasStatus_private int parentPid_private string openFilePath_private string connectionAddr_private ushort connectionPort_private bool hasConnection_ProcessQuery name(string pattern)Filters processes by name pattern.ProcessQuery exe(string pattern)Filters processes by executable path pattern.ProcessQuery user(string username)Filters processes by username.ProcessQuery cpuAbove(double percent)Filters processes with CPU usage above a threshold.ProcessQuery memoryAbove(ulong bytes)Filters processes with memory usage above a threshold.ProcessQuery status(ProcessStatus s)Filters processes by status.ProcessQuery parent(int pid)Filters processes by parent PID.ProcessQuery hasOpenFile(string path)Filters processes that have a specific file open.ProcessQuery hasConnection(string addr, ushort port)Filters processes that have a network connection.int count()Counts the number of processes matching the criteria.Represents a hierarchical tree of processes.
A ProcessTree contains a root process and its children (recursively). This is useful for visualizing process hierarchies and calculating aggregate statistics.
Example:
auto tree = processTree(1);
tree.visit((proc, depth) {
writeln(" ".repeat(depth), proc.name());
});void visit(void delegate(Process, int depth) visitor)Visits all processes in the tree using a visitor function.void visitImpl(void delegate(Process, int depth) visitor, int depth)Implementation of visit with depth tracking.ulong totalMemory()Calculates total memory usage of all processes in the tree.double totalCpu()Calculates total CPU usage of all processes in the tree.ProcessTree[] buildChildTrees(int parentPid) @safeRecursively builds child trees for a given parent PID.