Skip to main content

Module process

Module process 

Source
Expand description

Process operations and management.

This module provides ergonomic access to Windows process APIs including:

  • Opening and querying processes
  • Reading PEB (Process Environment Block) data
  • Enumerating threads and modules
  • Process tree operations
  • Memory information

§Examples

§Opening and querying a process

use windows_erg::process::{Process, ProcessId};

let process = Process::open(ProcessId::new(1234))?;
println!("Process name: {}", process.name()?);
println!("Process path: {}", process.path()?.display());

§Reading PEB data

use windows_erg::process::Process;

let process = Process::current();
println!("Command line: {}", process.command_line()?);

let env = process.environment()?;
for (key, value) in env {
    println!("{} = {}", key, value);
}

§Listing all processes

use windows_erg::process::Process;

let processes = Process::list()?;
for proc in processes {
    println!("{}: {}", proc.pid, proc.name);
}

§Using buffer reuse for performance

use windows_erg::process::Process;

let processes = Process::list()?;
let mut buffer = Vec::with_capacity(8192);

for proc_info in processes {
    if let Ok(process) = Process::open(proc_info.pid) {
        if let Ok(cmd) = process.command_line_with_buffer(&mut buffer) {
            println!("{}: {}", proc_info.name, cmd);
        }
    }
}

§Process tree operations

use windows_erg::process::{Process, ProcessId};

// Kill a process and all its children
let process = Process::open(ProcessId::new(1234))?;
process.kill_tree()?;

// Or kill entire tree from root ancestor
Process::kill_tree_from_root(ProcessId::new(1234))?;

Re-exports§

pub use types::ProcessId;
pub use types::ThreadId;

Structs§

HostMemoryMetrics
Point-in-time memory metrics for the host.
HostMetrics
Point-in-time metrics for the host.
MemoryInfo
Memory usage information.
ModuleInfo
Module (DLL) information.
Process
A handle to a Windows process.
ProcessCpuTimes
Process CPU time counters.
ProcessInfo
Basic process information.
ProcessMemoryMetrics
Extended process memory metrics.
ProcessMetrics
Point-in-time metrics for a process.
ProcessParameters
Process parameters from PEB.
ProcessSpawner
Builder for spawning processes with optional parent reparenting and token source.
SpawnedProcess
A spawned process with owned process/thread handles.
ThreadInfo
Thread information.

Enums§

ProcessAccess
Process access rights.

Functions§

host_cpu_usage
Calculate overall host CPU usage percentage over a sampling interval.
host_metrics
Get point-in-time host metrics.