Skip to content

Commit

Permalink
Merge pull request #1434 from GuillaumeGomez/improve-docs
Browse files Browse the repository at this point in the history
Improve documentation for `Process:kill*` and `Process::wait` methods
  • Loading branch information
GuillaumeGomez authored Dec 20, 2024
2 parents 98ccbfa + 10e2d8c commit 7c48259
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/common/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,15 +1135,16 @@ impl Process {
/// Sends [`Signal::Kill`] to the process (which is the only signal supported on all supported
/// platforms by this crate).
///
/// Returns `true` if the signal was sent successfully.
/// Returns `true` if the signal was sent successfully. If you want to wait for this process
/// to end, you can use [`Process::wait`].
///
/// ⚠️ Even if this function returns `true`, it doesn't necessarily mean that the process will
/// be killed. It just means that the signal was sent successfully.
///
/// ⚠️ Please note that some processes might not be "killable", like if they run with higher
/// levels than the current process for example.
///
/// If you want to send another signal, take a look at [`Process::kill_with`].
/// If you want to use another signal, take a look at [`Process::kill_with`].
///
/// To get the list of the supported signals on this system, use
/// [`SUPPORTED_SIGNALS`][crate::SUPPORTED_SIGNALS].
Expand All @@ -1164,7 +1165,8 @@ impl Process {
/// it'll do nothing and will return `None`. Otherwise it'll return `Some(bool)`. The boolean
/// value will depend on whether or not the signal was sent successfully.
///
/// If you just want to kill the process, use [`Process::kill`] directly.
/// If you just want to kill the process, use [`Process::kill`] directly. If you want to wait
/// for this process to end, you can use [`Process::wait`].
///
/// ⚠️ Please note that some processes might not be "killable", like if they run with higher
/// levels than the current process for example.
Expand All @@ -1186,6 +1188,23 @@ impl Process {
self.inner.kill_with(signal)
}

/// Wait for process termination.
///
/// ```no_run
/// use sysinfo::{Pid, System};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("Waiting for pid 1337");
/// process.wait();
/// println!("Pid 1337 exited");
/// }
/// ```
pub fn wait(&self) {
self.inner.wait()
}

/// Returns the name of the process.
///
/// **⚠️ Important ⚠️**
Expand Down Expand Up @@ -1569,23 +1588,6 @@ impl Process {
self.inner.effective_group_id()
}

/// Wait for process termination.
///
/// ```no_run
/// use sysinfo::{Pid, System};
///
/// let mut s = System::new_all();
///
/// if let Some(process) = s.process(Pid::from(1337)) {
/// println!("Waiting for pid 1337");
/// process.wait();
/// println!("Pid 1337 exited");
/// }
/// ```
pub fn wait(&self) {
self.inner.wait()
}

/// Returns the session ID for the current process or `None` if it couldn't
/// be retrieved.
///
Expand Down

0 comments on commit 7c48259

Please sign in to comment.