Skip to main content

Module process

Module process 

Source
Expand description

This process: its id, the user it runs as, whether it is elevated, and the process guard every long-running service starts with.

sys-lib does not list or inspect other processes.

use sys_lib as sys;

println!("pid {} as {}", sys::process::id(), sys::process::user()?.name);
if sys::process::is_elevated()? {
    println!("running as root or an elevated Administrator");
}

Structs§

CpuSampler
Measures this process’s CPU use between samples. Owned by the caller: two monitors keep two samplers and never disturb each other. sample never blocks and allocates nothing.
CpuTime
CPU time this process has used.
Guardguard
The running guard. Dropping it closes the lock file, which releases the lock; the lock file itself is never deleted (deleting it would let two copies run, see the plan’s guard section).
GuardBuilderguard
Options for Guard.
GuardReportguard
What the guard did.
InfoOptions
What info_with reads.
Limit
A resource limit: soft and hard values, None meaning unlimited or not applicable.
Limits
This process’s resource limits.
ProcessInfo
Everything about this process, in the fewest reads.
ProcessIo
How much this process has read from and written to storage since it started.
ProcessMemory
This process’s memory in detail.
ProcessUsage
The share of CPU this process used over an interval.
User
A user account.

Enums§

GuardWarningguard
A condition the guard reports without refusing to start.

Functions§

cpu_time
The CPU time this process has used so far: one system call, no allocation.
guardguard
Starts the process guard with secure defaults: a single-instance lock in path-lib’s runtime directory for name, umask(0o027), and the soft open-file limit raised to 65 536 (at least 1 024 required). Call it before any file is opened and before threads start, and keep the Guard for the life of the process.
id
This process’s id.
info
Everything about this process (Windows skips the thread count).
info_with
Everything about this process, with options.
io
How much this process has read from and written to storage, for a database’s own write amplification or a backup tool’s throughput. Two readings subtract; Rate::per turns the difference into a rate.
is_elevated
Whether this process runs as root, or with an elevated Administrator token.
limits
This process’s resource limits. Windows has no rlimit: the job object’s limits when there is one, otherwise every value None.
memory
This process’s resident memory (RSS): one read, no allocation.
memory_detail
This process’s memory in detail. Shipped with 0.4 so that info can carry it (D-044).
open_files
This process’s open file descriptors (Unix) or handles (Windows).
parent_id
This process’s parent, or None when it has none (an orphan adopted by init reports init) or the OS does not say. Windows: from a process snapshot, cached after the first call.
peak_memory
The highest resident memory this process has reached.
started_at
When this process started.
threads
This process’s threads. Linux and macOS: one read, no allocation. Windows: a system-wide thread snapshot, whose cost grows with the machine’s thread count.
user
The effective user this process runs as now.