Skip to content

Commit

Permalink
process: stabilize Command::process_group
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Jul 27, 2024
1 parent f602eae commit 23958ba
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions tokio/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,29 +751,34 @@ impl Command {
///
/// Process groups determine which processes receive signals.
///
/// **Note**: This is an [unstable API][unstable] but will be stabilised once
/// tokio's `MSRV` is sufficiently new. See [the documentation on
/// unstable features][unstable] for details about using unstable features.
/// # Examples
///
/// Pressing Ctrl-C in a terminal will send SIGINT to all processes
/// in the current foreground process group. By spawning the `sleep`
/// subprocess in a new process group, it will not receive SIGINT
/// from the terminal.
///
/// If you want similar behavior without using this unstable feature you can
/// create a [`std::process::Command`] and convert that into a
/// [`tokio::process::Command`] using the `From` trait.
/// The parent process could install a [signal handler] and manage the
/// process on its own terms.
///
/// [unstable]: crate#unstable-features
/// [`tokio::process::Command`]: crate::process::Command
/// A process group ID of 0 will use the process ID as the PGID.
///
/// ```no_run
/// # async fn test() { // allow using await
/// use tokio::process::Command;
///
/// let output = Command::new("ls")
/// .process_group(0)
/// .output().await.unwrap();
/// let output = Command::new("sleep")
/// .arg("10")
/// .process_group(0)
/// .output()
/// .await
/// .unwrap();
/// # }
/// ```
///
/// [signal handler]: crate::signal
#[cfg(unix)]
#[cfg(tokio_unstable)]
#[cfg_attr(docsrs, doc(cfg(all(unix, tokio_unstable))))]
#[cfg_attr(docsrs, doc(cfg(unix)))]
pub fn process_group(&mut self, pgroup: i32) -> &mut Command {
self.std.process_group(pgroup);
self
Expand Down

0 comments on commit 23958ba

Please sign in to comment.