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§

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.
Limit
A resource limit: soft and hard values, None meaning unlimited or not applicable.
User
A user account.

Enums§

GuardWarningguard
A condition the guard reports without refusing to start.

Functions§

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.
is_elevated
Whether this process runs as root, or with an elevated Administrator token.
user
The effective user this process runs as now.