Skip to main content

Process

Trait Process 

Source
pub trait Process: AsHandle + AsRawHandle {
    type Handle;

Show 24 methods // Required methods fn borrowed(&self) -> BorrowedProcess<'_>; fn try_clone(&self) -> Result<Self, Error> where Self: Sized; fn into_handle(self) -> Self::Handle; unsafe fn from_handle_unchecked(handle: Self::Handle) -> Self; fn current_handle() -> Self::Handle; fn find_module_by_name( &self, module_name: impl AsRef<Path>, ) -> Result<Option<ProcessModule<Self>>, Error> where Self: Sized; fn find_module_by_path( &self, module_path: impl AsRef<Path>, ) -> Result<Option<ProcessModule<Self>>, Error> where Self: Sized; fn wait_for_module_by_name( &self, module_name: impl AsRef<Path>, timeout: Duration, ) -> Result<Option<ProcessModule<Self>>, Error> where Self: Sized; fn wait_for_module_by_path( &self, module_path: impl AsRef<Path>, timeout: Duration, ) -> Result<Option<ProcessModule<Self>>, Error> where Self: Sized; // Provided methods fn raw_current_handle() -> ProcessHandle { ... } fn current() -> Self where Self: Sized { ... } fn is_current(&self) -> bool { ... } fn is_alive(&self) -> bool { ... } fn pid(&self) -> Result<NonZeroU32, Error> { ... } fn runs_under_wow64(&self) -> Result<bool, Error> { ... } fn is_x64(&self) -> Result<bool, Error> { ... } fn is_x86(&self) -> Result<bool, Error> { ... } fn path(&self) -> Result<PathBuf, Error> { ... } fn base_name(&self) -> Result<OsString, Error> { ... } fn kill(&self) -> Result<(), Error> { ... } fn kill_with_exit_code(&self, exit_code: u32) -> Result<(), Error> { ... } fn run_remote_thread<T>( &self, remote_fn: extern "system" fn(*mut T) -> u32, parameter: *mut T, ) -> Result<u32, Error> { ... } fn start_remote_thread<T>( &self, remote_fn: unsafe extern "system" fn(*mut T) -> u32, parameter: *mut T, ) -> Result<OwnedHandle, Error> { ... } fn modules(&self) -> Result<Vec<ProcessModule<Self>>, Error> where Self: Sized { ... }
}
Available on Windows only.
Expand description

A trait representing a running process.

§Note

The underlying handle has the following privileges:

  • PROCESS_CREATE_THREAD
  • PROCESS_QUERY_INFORMATION
  • PROCESS_VM_OPERATION
  • PROCESS_VM_WRITE
  • PROCESS_VM_READ

Required Associated Types§

Source

type Handle

The underlying handle type.

Required Methods§

Source

fn borrowed(&self) -> BorrowedProcess<'_>

Returns a borrowed instance of this process.

Source

fn try_clone(&self) -> Result<Self, Error>
where Self: Sized,

Tries to clone this process into a new instance.

Source

fn into_handle(self) -> Self::Handle

Returns the underlying process handle.

Source

unsafe fn from_handle_unchecked(handle: Self::Handle) -> Self

Creates a new instance from the given handle.

§Safety

The caller must ensure that the handle is a valid process handle and has the required priviledges.

Source

fn current_handle() -> Self::Handle

Returns the pseudo handle representing the current process.

Source

fn find_module_by_name( &self, module_name: impl AsRef<Path>, ) -> Result<Option<ProcessModule<Self>>, Error>
where Self: Sized,

Searches the modules in this process for one with the given name. The comparison of names is case-insensitive. If the extension is omitted, the default library extension .dll is appended.

§Note

If the process is currently starting up and has not loaded all its modules, the returned list may be incomplete. See also Process::wait_for_module_by_name.

Source

fn find_module_by_path( &self, module_path: impl AsRef<Path>, ) -> Result<Option<ProcessModule<Self>>, Error>
where Self: Sized,

Searches the modules in this process for one with the given path. The comparison of paths is case-insensitive. If the extension is omitted, the default library extension .dll is appended.

§Note

If the process is currently starting up and has not loaded all its modules, the returned list may be incomplete. See also Process::wait_for_module_by_path.

Source

fn wait_for_module_by_name( &self, module_name: impl AsRef<Path>, timeout: Duration, ) -> Result<Option<ProcessModule<Self>>, Error>
where Self: Sized,

Searches the modules in this process for one with the given name, repeatedly until a matching module is found or the given timeout elapses. The comparison of names is case-insensitive. If the extension is omitted, the default library extension .dll is appended.

Source

fn wait_for_module_by_path( &self, module_path: impl AsRef<Path>, timeout: Duration, ) -> Result<Option<ProcessModule<Self>>, Error>
where Self: Sized,

Searches the modules in this process for one with the given path, repeatedly until a matching module is found or the given timeout elapses. The comparison of paths is case-insensitive. If the extension is omitted, the default library extension .dll is appended.

Provided Methods§

Source

fn raw_current_handle() -> ProcessHandle

Returns the raw pseudo handle representing the current process.

Source

fn current() -> Self
where Self: Sized,

Returns an instance representing the current process.

Source

fn is_current(&self) -> bool

Returns whether this instance represents the current process.

Source

fn is_alive(&self) -> bool

Returns whether this process is still alive and running.

§Note

If the operation to determine the status fails, this function assumes that the process has exited.

Source

fn pid(&self) -> Result<NonZeroU32, Error>

Returns the id of this process.

Source

fn runs_under_wow64(&self) -> Result<bool, Error>

Returns whether this process is running under WOW64. This is the case for 32-bit programs running on a 64-bit platform.

§Note

This method also returns false for a 32-bit process running under 32-bit Windows or 64-bit Windows 10 on ARM.

Source

fn is_x64(&self) -> Result<bool, Error>

Returns whether this process is a 64-bit process.

Source

fn is_x86(&self) -> Result<bool, Error>

Returns whether this process is a 32-bit process.

Source

fn path(&self) -> Result<PathBuf, Error>

Returns the executable path of this process.

Source

fn base_name(&self) -> Result<OsString, Error>

Returns the file name of the executable of this process.

Source

fn kill(&self) -> Result<(), Error>

Terminates this process with exit code 1.

Source

fn kill_with_exit_code(&self, exit_code: u32) -> Result<(), Error>

Terminates this process with the given exit code.

Source

fn run_remote_thread<T>( &self, remote_fn: extern "system" fn(*mut T) -> u32, parameter: *mut T, ) -> Result<u32, Error>

Starts a new thread in this process with the given entry point and argument, and waits for it to finish, returning the exit code.

Source

fn start_remote_thread<T>( &self, remote_fn: unsafe extern "system" fn(*mut T) -> u32, parameter: *mut T, ) -> Result<OwnedHandle, Error>

Starts a new thread in this process with the given entry point and argument and returns the thread handle.

Source

fn modules(&self) -> Result<Vec<ProcessModule<Self>>, Error>
where Self: Sized,

Returns a snapshot of all modules currently loaded in this process.

§Note

If the process is currently starting up and has not loaded all its modules yet, the returned list may be incomplete.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§