Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: Add process_group method to Command struct #5114

Merged
merged 2 commits into from Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Expand Up @@ -2,7 +2,7 @@ freebsd_instance:
image: freebsd-12-3-release-amd64
env:
RUST_STABLE: stable
RUST_NIGHTLY: nightly-2022-03-21
RUST_NIGHTLY: nightly-2022-10-25
RUSTFLAGS: -D warnings

# Test FreeBSD in a full VM on cirrus-ci.com. Test the i686 target too, in the
Expand Down
30 changes: 30 additions & 0 deletions tokio/src/process/mod.rs
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.
Comment on lines +693 to +696
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should document that it is unstable, how to enable unstable features (a link is fine - see doc for other unstable methods), and that it will become stable when our MSRV is new enough to allow this in a stable manner. It would also be nice to mention that you can do this today by constructing an std::process::Command and using our From impl to convert it.

///
/// **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
2 changes: 1 addition & 1 deletion tokio/src/runtime/task/mod.rs
Expand Up @@ -121,7 +121,7 @@
//! 1. The output is created on the thread that the future was polled on. Since
//! only non-Send futures can have non-Send output, the future was polled on
//! the thread that the future was spawned from.
//! 2. Since JoinHandle<Output> is not Send if Output is not Send, the
//! 2. Since `JoinHandle<Output>` is not Send if Output is not Send, the
//! JoinHandle is also on the thread that the future was spawned from.
//! 3. Thus, the JoinHandle will not move the output across threads when it
//! takes or drops the output.
Expand Down