ddn.util.monaco.query

Advanced Process Querying

This module provides powerful filtering and search capabilities for processes, including a fluent query API and process tree construction.

Features:

  • Fluent query DSL for process filtering
  • Pattern matching (glob-style)
  • Process tree construction
  • Aggregate statistics
  • Performance optimized

Platform Availability:

  • Fully cross-platform
  • Linux, Windows, macOS, BSD

Types 2

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();

Methods
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.
Process[] execute()Executes the query and returns matching processes.
int count()Counts the number of processes matching the criteria.
Process first()Returns the first process 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());
});

Fields
Process rootThe root process of this tree node
ProcessTree[] childrenChild process trees
Methods
void visit(void delegate(Process, int depth) visitor)Visits all processes in the tree using a visitor function.
Process[] flatten()Flattens the tree into a single array of processes.
ulong totalMemory()Calculates total memory usage of all processes in the tree.
double totalCpu()Calculates total CPU usage of all processes in the tree.

Functions 2

fnProcessTree processTree(int rootPid) @safeBuilds a process tree starting from a specific PID.
fnProcessTree[] processForest() @safeBuilds process trees for all top-level processes.