]> git.lizzy.rs Git - rust.git/commitdiff
Document and stabilize process_set_process_group
authorNiklas Fiekas <niklas.fiekas@backscattering.de>
Wed, 15 Jun 2022 22:12:03 +0000 (00:12 +0200)
committerNiklas Fiekas <niklas.fiekas@backscattering.de>
Sat, 9 Jul 2022 10:40:33 +0000 (12:40 +0200)
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

index 5065530e8d4d003b8e373aed9ba4bcfa5e7a0ff1..bd6d431f8e420b13505fc7bec0f233a0b3cf623d 100644 (file)
@@ -148,9 +148,34 @@ fn arg0<S>(&mut self, arg: S) -> &mut process::Command
     where
         S: AsRef<OsStr>;
 
-    /// 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<dyn std::error::Error>>(())
+    /// ```
+    #[stable(feature = "process_set_process_group", since = "1.64.0")]
     fn process_group(&mut self, pgroup: i32) -> &mut process::Command;
 }