pub struct Process(/* private fields */);
Expand description
System process.
Some extra methods can be found in the OS extensions
Implementations§
Source§impl Process
impl Process
Sourcepub fn parent_pid(&self) -> impl Future<Output = ProcessResult<Pid>>
pub fn parent_pid(&self) -> impl Future<Output = ProcessResult<Pid>>
Returns future which resolves into the process parent pid.
Sourcepub fn parent(&self) -> impl Future<Output = ProcessResult<Process>>
pub fn parent(&self) -> impl Future<Output = ProcessResult<Process>>
Returns future which resolves into the parent Process.
Sourcepub fn name(&self) -> impl Future<Output = ProcessResult<String>>
pub fn name(&self) -> impl Future<Output = ProcessResult<String>>
Returns future which resolves into the process name.
Sourcepub fn exe(&self) -> impl Future<Output = ProcessResult<PathBuf>>
pub fn exe(&self) -> impl Future<Output = ProcessResult<PathBuf>>
Returns future which resolves into the process executable as an absolute path.
Sourcepub fn command(&self) -> impl Future<Output = ProcessResult<Command>>
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);
}
Sourcepub fn cwd(&self) -> impl Future<Output = ProcessResult<PathBuf>>
pub fn cwd(&self) -> impl Future<Output = ProcessResult<PathBuf>>
Sourcepub fn status(&self) -> impl Future<Output = ProcessResult<Status>>
pub fn status(&self) -> impl Future<Output = ProcessResult<Status>>
Returns future which resolves into the current process status.
Sourcepub fn create_time(&self) -> impl Future<Output = ProcessResult<Time>>
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.
Sourcepub fn cpu_time(&self) -> impl Future<Output = ProcessResult<CpuTime>>
pub fn cpu_time(&self) -> impl Future<Output = ProcessResult<CpuTime>>
Returns future which resolves into the accumulated process time.
Sourcepub fn cpu_usage(&self) -> impl Future<Output = ProcessResult<CpuUsage>>
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>());
Sourcepub fn memory(&self) -> impl Future<Output = ProcessResult<Memory>>
pub fn memory(&self) -> impl Future<Output = ProcessResult<Memory>>
Returns future which resolves into the memory information about this process.
Sourcepub fn is_running(&self) -> impl Future<Output = ProcessResult<bool>>
pub fn is_running(&self) -> impl Future<Output = ProcessResult<bool>>
Returns future which checks if this Process
is still running.
Sourcepub fn suspend(&self) -> impl Future<Output = ProcessResult<()>>
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.
Sourcepub fn resume(&self) -> impl Future<Output = ProcessResult<()>>
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.
Sourcepub fn terminate(&self) -> impl Future<Output = ProcessResult<()>>
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
Sourcepub fn kill(&self) -> impl Future<Output = ProcessResult<()>>
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.