ddn.util.monaco.advanced

Advanced Process Control Features

This module provides advanced process control functionality that goes beyond basic monitoring, leveraging D's unique capabilities for system programming.

Features:

  • Process affinity control (CPU pinning)
  • Nice/priority management
  • Process environment modification
  • cgroup support (Linux)
  • Process namespaces (Linux)
  • Job objects (Windows)
  • Process monitoring callbacks
  • Event-driven process notifications

Types 5

Process priority levels

HIGHHigh priority (requires privileges)
ABOVE_NORMALAbove normal priority
NORMALNormal priority (default)
BELOW_NORMALBelow normal priority
LOWLow priority / background
IDLEIdle priority (lowest)

Process monitoring event types

CREATEDProcess was created
TERMINATEDProcess terminated
STATUS_CHANGEDProcess status changed
CPU_HIGHCPU usage exceeded threshold
MEMORY_HIGHMemory usage exceeded threshold
FILE_OPENEDProcess opened a file
NET_CONNECTEDProcess established network connection

Process monitoring event

Fields
int pid
SysTime timestamp
string details
aliasProcessCallback = void delegate(ProcessEvent event)

Process monitor callback type

Process monitor for event-driven notifications.

This class provides functionality to monitor process events and invoke callbacks when specific events occur.

Example:

auto monitor = new ProcessMonitor();
monitor.onProcessCreated((event) {
   writeln("New process: ", event.pid);
});
monitor.start();

Fields
private ProcessCallback _onCreated
private ProcessCallback _onTerminated
private ProcessCallback _onStatusChanged
private Thread _monitorThread
private bool _running
private Duration _interval
Methods
void onProcessCreated(ProcessCallback callback) @safe nothrowSets callback for process creation events.
void onProcessTerminated(ProcessCallback callback) @safe nothrowSets callback for process termination events.
void onProcessStatusChanged(ProcessCallback callback) @safe nothrowSets callback for process status change events.
void setInterval(Duration interval) @safe nothrowSets the monitoring interval.
void start() @trustedStarts monitoring processes.
void stop() @trustedStops monitoring processes.
private void monitorLoop() @trusted
private bool canFind(int[] arr, int val) @safe nothrow
Constructors
this()Creates a new process monitor.

Functions 5

fnvoid setProcessPriority(int pid, ProcessPriority priority) @trustedSets process priority/nice value.
fnProcessPriority getProcessPriority(int pid) @trustedGets the current process priority/nice value.
fnvoid setEnvironmentVar(string key, string value) @trusted nothrowSets an environment variable for a process.
fnvoid removeEnvironmentVar(string key) @trusted nothrowRemoves an environment variable from the current process.
fnProcessMonitor monitorProcess(int pid, ProcessCallback callback, Duration interval = 100.msecs) @safeConvenience function to monitor a single process.