Skip to content

Commit 49b9cb2

Browse files
committed
add documentation, remove &mut
1 parent 725b684 commit 49b9cb2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

library/std/src/os/unix/process.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,34 @@ impl ExitStatusExt for process::ExitStatusError {
380380

381381
#[unstable(feature = "unix_send_signal", issue = "141975")]
382382
pub trait ChildExt: Sealed {
383-
fn send_signal(&mut self, signal: i32) -> io::Result<()>;
383+
/// Sends a signal to a child process.
384+
///
385+
/// # Errors
386+
///
387+
/// This function will return an error if the signal is invalid. The integer values associated
388+
/// with signals are implemenation-specific, so the use of [`libc`] is encouraged.
389+
///
390+
/// # Examples
391+
///
392+
/// ```rust
393+
/// #![feature(unix_send_signal)]
394+
///
395+
/// use std::{io, os::unix::process::ChildExt, process::{Command, Stdio}};
396+
///
397+
/// use libc::SIGTERM;
398+
///
399+
/// fn main() -> io::Result<()> {
400+
/// let child = Command::new("cat").stdin(Stdio::piped()).spawn()?;
401+
/// child.send_signal(SIGTERM)?;
402+
/// Ok(())
403+
/// }
404+
/// ```
405+
fn send_signal(&self, signal: i32) -> io::Result<()>;
384406
}
385407

386408
#[unstable(feature = "unix_send_signal", issue = "141975")]
387409
impl ChildExt for process::Child {
388-
fn send_signal(&mut self, signal: i32) -> io::Result<()> {
410+
fn send_signal(&self, signal: i32) -> io::Result<()> {
389411
self.handle.send_signal(signal)
390412
}
391413
}

library/std/src/sys/process/unix/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl Process {
967967
self.send_signal(libc::SIGKILL)
968968
}
969969

970-
pub(crate) fn send_signal(&mut self, signal: i32) -> io::Result<()> {
970+
pub(crate) fn send_signal(&self, signal: i32) -> io::Result<()> {
971971
// If we've already waited on this process then the pid can be recycled
972972
// and used for another process, and we probably shouldn't be signaling
973973
// random processes, so return Ok because the process has exited already.

0 commit comments

Comments
 (0)