From c4edb3ac5463607b29d5925bb457af3bd842c7ad Mon Sep 17 00:00:00 2001 From: Harvey Hunt Date: Fri, 21 Oct 2022 13:49:04 +0100 Subject: [PATCH] command: Add process_group method to Command struct Rust 1.64 stabilised the `process_group` method of the `std::os::unix::process::CommandExt` trait. This allows the caller to set the process group that a command is spawned in. Expose that functionality from Tokio's `Command` structure. This fixes #4312. --- tokio/src/process/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tokio/src/process/mod.rs b/tokio/src/process/mod.rs index e5ee5db2ba0..959ca6b09ee 100644 --- a/tokio/src/process/mod.rs +++ b/tokio/src/process/mod.rs @@ -690,6 +690,28 @@ impl Command { self } + /// Sets the process group ID (PGID) of the child process. Equivalent to a + /// setpgid call in the child process, but may be more efficient. + /// + /// Process groups determine which processes receive signals. + /// + /// ```no_run + /// use tokio::process::Command; + /// + /// Command::new("ls") + /// .process_group(0) + /// .spawn()? + /// .await + /// .wait()?; + /// ``` + #[cfg(unix)] + #[cfg_attr(docsrs, doc(cfg(unix)))] + #[cfg(tokio_unstable)] + pub fn process_group(&mut self, pgroup: i32) -> &mut Command { + self.std.process_group(pgroup); + self + } + /// Executes the command as a child process, returning a handle to it. /// /// By default, stdin, stdout and stderr are inherited from the parent.