Skip to content

Commit b028bbf

Browse files
committed
Document and stabilize process_set_process_group
Tracking issue: rust-lang#93857 FCP finished here: rust-lang#93857 (comment)
1 parent 86b8dd5 commit b028bbf

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

library/std/src/os/unix/process.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,34 @@ pub trait CommandExt: Sealed {
148148
where
149149
S: AsRef<OsStr>;
150150

151-
/// Sets the process group ID of the child process. Translates to a `setpgid` call in the child
152-
/// process.
153-
#[unstable(feature = "process_set_process_group", issue = "93857")]
151+
/// Sets the process group ID of the child process. Equivalent to a
152+
/// `setpgid` call in the child process, but may be more efficient.
153+
///
154+
/// Process groups determine which processes receive signals.
155+
///
156+
/// # Examples
157+
///
158+
/// Pressing Ctrl-C in a terminal will send SIGINT to all processes in
159+
/// the current foreground process group. By spawning the `sleep`
160+
/// subprocess in a new process group, it will not receive SIGINT from the
161+
/// terminal.
162+
///
163+
/// The parent process could install a signal handler and manage the
164+
/// subprocess on its own terms.
165+
///
166+
/// ```no_run
167+
/// use std::process::Command;
168+
/// use std::os::unix::process::CommandExt;
169+
///
170+
/// Command::new("sleep")
171+
/// .arg("10")
172+
/// .process_group(0)
173+
/// .spawn()?
174+
/// .wait()?;
175+
/// #
176+
/// # Ok::<_, Box<dyn std::error::Error>>(())
177+
/// ```
178+
#[stable(feature = "process_set_process_group", since = "1.64.0")]
154179
fn process_group(&mut self, pgroup: i32) -> &mut process::Command;
155180
}
156181

0 commit comments

Comments
 (0)