heim_process

Struct Process

Source
pub struct Process(/* private fields */);
Expand description

System process.

Some extra methods can be found in the OS extensions

Implementations§

Source§

impl Process

Source

pub fn pid(&self) -> Pid

Returns the process pid.

Source

pub fn parent_pid(&self) -> impl Future<Output = ProcessResult<Pid>>

Returns future which resolves into the process parent pid.

Source

pub fn parent(&self) -> impl Future<Output = ProcessResult<Process>>

Returns future which resolves into the parent Process.

Source

pub fn name(&self) -> impl Future<Output = ProcessResult<String>>

Returns future which resolves into the process name.

Source

pub fn exe(&self) -> impl Future<Output = ProcessResult<PathBuf>>

Returns future which resolves into the process executable as an absolute path.

Source

pub fn command(&self) -> impl Future<Output = ProcessResult<Command>>

Returns future which resolves into the process command line.

§Example
let process = process::current().await?;
let command = process.command().await?;
println!("Command line arguments:");
for arg in &command {
    println!("{:?}", arg);
}
Source

pub fn cwd(&self) -> impl Future<Output = ProcessResult<PathBuf>>

Returns future which resolves into the process current working directory.

§Compatibility

For Windows this method is not implemented yet and will always return an error, see #105.

Source

pub fn status(&self) -> impl Future<Output = ProcessResult<Status>>

Returns future which resolves into the current process status.

Source

pub fn create_time(&self) -> impl Future<Output = ProcessResult<Time>>

Returns future which resolves into the process creation time, expressed as a Time amount since the UNIX epoch.

Source

pub fn cpu_time(&self) -> impl Future<Output = ProcessResult<CpuTime>>

Returns future which resolves into the accumulated process time.

Source

pub fn cpu_usage(&self) -> impl Future<Output = ProcessResult<CpuUsage>>

Returns future which resolves into the CPU usage measurement.

Returned CpuUsage struct represents instantaneous CPU usage and does not represent any reasonable value by itself. It is suggested to wait for a while with help of any async timer (for accuracy recommended delay should be at least 100 ms), call this method once again and subtract former CpuUsage from the new one.

Same to any *nix system, calculated CPU usage might exceed 100 % if the process is running multiple threads on different CPU cores.

§Example
let process = process::current().await?;
let measurement_1 = process.cpu_usage().await?;
// Or any other async timer at your choice
futures_timer::Delay::new(Duration::from_millis(100)).await;
let measurement_2 = process.cpu_usage().await?;

println!("CPU usage: {} %", (measurement_2 - measurement_1).get::<ratio::percent>());
Source

pub fn memory(&self) -> impl Future<Output = ProcessResult<Memory>>

Returns future which resolves into the memory information about this process.

Source

pub fn is_running(&self) -> impl Future<Output = ProcessResult<bool>>

Returns future which checks if this Process is still running.

Source

pub fn suspend(&self) -> impl Future<Output = ProcessResult<()>>

Suspend the current process.

Before the signal send, it checks whether process PID has been reused, and if it is a case, NoSuchProcess error will be returned.

§Compatibility

For *nix systems it sends the SIGSTOP signal to process.

Source

pub fn resume(&self) -> impl Future<Output = ProcessResult<()>>

Resume the current process.

Before the signal send, it checks whether process PID has been reused, and if it is a case, NoSuchProcess error will be returned.

§Compatibility

For *nix systems it sends the SIGCONT signal to process.

Source

pub fn terminate(&self) -> impl Future<Output = ProcessResult<()>>

Terminate the current process.

Before the signal send, it checks whether process PID has been reused, and if it is a case, NoSuchProcess error will be returned.

§Compatibility

For *nix systems it sends the SIGTERM signal to process.

For Windows it is an alias for the Process::kill

Source

pub fn kill(&self) -> impl Future<Output = ProcessResult<()>>

Kills the current process.

Before the signal send, it checks whether process PID has been reused, and if it is a case, NoSuchProcess error will be returned.

§Compatibility

For *nix systems it sends the SIGKILL signal to process.

TerminateProcess function is used for Windows, it initiates the termination but does not awaits for completion.

Trait Implementations§

Source§

impl Debug for Process

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Process

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Process

Source§

fn eq(&self, other: &Process) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ProcessExt for Process

Source§

fn signal(&self, signal: Signal) -> BoxFuture<'_, ProcessResult<()>>

Send the signal to process. Read more
Source§

impl ProcessExt for Process

Source§

fn io_counters(&self) -> BoxFuture<'_, ProcessResult<IoCounters>>

Returns future which resolves into process IO counters. Read more
Source§

fn net_io_counters(&self) -> BoxStream<'_, ProcessResult<IoCounters>>

Returns stream which yield this process IO counters for each network interface. Read more
Source§

impl Eq for Process

Source§

impl StructuralPartialEq for Process

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.