ddn.util.monaco.process

Types 4

classProcess

Represents a system process.

This class provides access to process information and control operations. It handles PID reuse by tracking process creation time for identity verification.

Example:

auto proc = Process.current();
writeln("Process: ", proc.name());
writeln("PID: ", proc.pid());
writeln("Status: ", proc.status());

Fields
private int _pid
private SysTime _createTime
private string _name
private string _exe
private string _cwd
private string _cmdline
private string _username
private ProcessStatus _status
private int _ppid
Methods
Process current() @trustedGets a Process object for the current process.
int pid() @property const @safe nothrowGets the process ID.
string name() @property @safeGets the process name.
string exe() @property @safeGets the full path to the process executable.
string cwd() @property @safeGets the current working directory of the process.
string cmdline() @property @safeGets the command line arguments of the process.
ProcessStatus status() @property @safeGets the current status of the process.
string username() @property @safeGets the username of the process owner.
SysTime createTime() @property @safeGets the process creation time.
Process parent() @property @safeGets the parent process.
Process[] children(bool recursive = false) @trustedGets child processes of this process.
bool isRunning() @safeChecks if the process is still running.
void wait(Duration timeout = Duration.max) @trustedWaits for the process to terminate.
void terminate() @trustedTerminates the process gracefully (SIGTERM on Unix).
void kill() @trustedKills the process forcefully (SIGKILL on Unix).
void suspend() @trustedSuspends the process (SIGSTOP on Unix).
void resume() @trustedResumes a suspended process (SIGCONT on Unix).
size_t toHash() const @safe nothrowComputes a hash value for the process.
bool opEquals(const Process other) const @safe nothrowCompares two Process objects for equality.
CpuTimes cpuTimes() @safeGets CPU times for this process.
double cpuPercent(Duration interval = Duration.zero) @safeGets CPU usage percentage.
MemoryInfo memoryInfo() @safeGets memory information for this process.
double memoryPercent() @safeGets memory usage percentage.
IoCounters ioCounters() @trustedGets I/O counters for this process.
int numThreads() @safeGets the number of threads in this process.
ThreadInfo[] threads() @trustedGets information about threads in this process.
OpenFile[] openFiles() @trustedGets open files for this process.
NetConnection[] connections(string kind = "inet") @trustedGets network connections for this process.
string[string] environ() @trustedGets environment variables for this process.
Constructors
this(int pid)Creates a Process object for the given PID.
Nested Templates
CpuTimesCPU times for a process.
MemoryInfoMemory information for a process.
IoCountersI/O counters for a process.
ThreadInfoThread information.
OpenFileOpen file information.
aliaspids = allPids

Gets all process IDs in the system.

This is an alias for allPids() to match the PLAN API.

Returns

Array of all process IDs.

Example:

auto allPids = pids();
writeln("Total processes: ", allPids.length);

Result of process enumeration with error information.

This struct contains successfully enumerated processes along with information about any failures that occurred during enumeration.

Fields
Process[] processes
int[] failedPids
string[int] errors

Process iterator range.

This struct provides a range interface for iterating over processes.

Fields
private int[] _pids
private size_t _index
private string[] _attrs
private bool _preload
Methods
bool empty() const @safe nothrowChecks if the range is empty.
Process front() @safeGets the current Process.
void popFront() @safe nothrowAdvances to the next process.
ProcessRange save() const @safe nothrowSaves the current position.
size_t length() const @safe nothrowGets the length of the range.

Functions 9

fnint[] allPids() @trustedGets a list of all process PIDs.
fnbool pidExists(int pid) @trustedChecks if a process with the given PID exists.
private fnbool canFind(T)(T[] arr, T val) @safe
private fnbool startsWith(string str, string prefix) @safe @nogc nothrow
fnProcess[] allProcesses() @safeGets all processes as Process objects.
fnProcessEnumerationResult allProcessesWithErrors() @safeGets all processes with error information.
fnProcess[] findProcsByName(string name, bool ignoreCase = false) @safeFinds processes by name.
fnProcessRange processIter(string[] attrs = null, bool preload = false) @safeCreates a process iterator.
fnbool waitProcs(Process[] procs, Duration timeout = Duration.max, out Process[] gone, out Process[] alive) @safeWaits for multiple processes to terminate.