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.
samplenever blocks and allocates nothing. - CpuTime
- CPU time this process has used.
- Guard
guard - 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).
- Guard
Builder guard - Options for
Guard. - Guard
Report guard - What the guard did.
- Info
Options - What
info_withreads. - Limit
- A resource limit: soft and hard values,
Nonemeaning unlimited or not applicable. - Limits
- This process’s resource limits.
- Process
Info - Everything about this process, in the fewest reads.
- Process
Io - How much this process has read from and written to storage since it started.
- Process
Memory - This process’s memory in detail.
- Process
Usage - The share of CPU this process used over an interval.
- User
- A user account.
Enums§
- Guard
Warning guard - 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.
- guard
guard - 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 theGuardfor 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::perturns 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 valueNone. - 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
infocan carry it (D-044). - open_
files - This process’s open file descriptors (Unix) or handles (Windows).
- parent_
id - This process’s parent, or
Nonewhen 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.