Skip to content

Commit

Permalink
command: Add process_group method to Command struct
Browse files Browse the repository at this point in the history
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,
behind the unstable feature.

This fixes tokio-rs#4312.
  • Loading branch information
HarveyHunt committed Oct 27, 2022
1 parent aae33d3 commit 1763601
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tokio/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,36 @@ 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.
///
/// **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.
///
/// If you want similar behaviour without using this unstable feature you can
/// create a [`std::process::Command`] and convert that into a
/// [`tokio::process::Command`] using the `From` trait.
///
/// [unstable]: crate#unstable-features
/// [`tokio::process::Command`]: crate::process::Command
///
/// ```no_run
/// use tokio::process::Command;
///
/// let command = Command::new("ls")
/// .process_group(0);
/// ```
#[cfg(unix)]
#[cfg(tokio_unstable)]
#[cfg_attr(docsrs, doc(cfg(all(unix, 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.
Expand Down

0 comments on commit 1763601

Please sign in to comment.