From b028bbf9d0618f0f4af279d33b7a057a8072eb18 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Thu, 16 Jun 2022 00:12:03 +0200 Subject: [PATCH 1/2] Document and stabilize process_set_process_group Tracking issue: https://github.com/rust-lang/rust/issues/93857 FCP finished here: https://github.com/rust-lang/rust/issues/93857#issuecomment-1179551697 --- library/std/src/os/unix/process.rs | 31 +++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 5065530e8d4d0..bd6d431f8e420 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -148,9 +148,34 @@ pub trait CommandExt: Sealed { where S: AsRef; - /// Sets the process group ID of the child process. Translates to a `setpgid` call in the child - /// process. - #[unstable(feature = "process_set_process_group", issue = "93857")] + /// Sets the process group ID 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. + /// + /// # 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. + /// + /// The parent process could install a signal handler and manage the + /// subprocess on its own terms. + /// + /// ```no_run + /// use std::process::Command; + /// use std::os::unix::process::CommandExt; + /// + /// Command::new("sleep") + /// .arg("10") + /// .process_group(0) + /// .spawn()? + /// .wait()?; + /// # + /// # Ok::<_, Box>(()) + /// ``` + #[stable(feature = "process_set_process_group", since = "1.64.0")] fn process_group(&mut self, pgroup: i32) -> &mut process::Command; } From 629b0b488b3e84ce389c71a10ca3ca976bf05d92 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 16 Jul 2022 14:45:16 -0700 Subject: [PATCH 2/2] Expand documentation for `process_group` Explain PGID 0, and provide the acronym PGID. --- library/std/src/os/unix/process.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index bd6d431f8e420..09b2bfe39f094 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -148,7 +148,7 @@ pub trait CommandExt: Sealed { where S: AsRef; - /// Sets the process group ID of the child process. Equivalent to a + /// 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. @@ -163,6 +163,8 @@ pub trait CommandExt: Sealed { /// The parent process could install a signal handler and manage the /// subprocess on its own terms. /// + /// A process group ID of 0 will use the process ID as the PGID. + /// /// ```no_run /// use std::process::Command; /// use std::os::unix::process::CommandExt;