Skip to main content

rskit_process/command/
signal.rs

1//! Signal and process-tree termination policy.
2
3use std::time::Duration;
4
5/// Signal and process-tree termination policy.
6#[derive(Debug, Clone, Copy, Eq, PartialEq)]
7#[non_exhaustive]
8pub struct SignalPolicy {
9    /// Grace period to wait after graceful termination before killing.
10    pub grace_period: Duration,
11    /// Create a new process group/session where supported.
12    pub create_process_group: bool,
13    /// Terminate the process group rather than only the immediate child where supported.
14    pub terminate_descendants: bool,
15}
16
17impl Default for SignalPolicy {
18    fn default() -> Self {
19        Self {
20            grace_period: Duration::from_secs(5),
21            create_process_group: true,
22            terminate_descendants: true,
23        }
24    }
25}
26
27impl SignalPolicy {
28    /// Set the graceful termination period before kill escalation.
29    #[must_use]
30    pub fn with_grace_period(mut self, grace_period: Duration) -> Self {
31        self.grace_period = grace_period;
32        self
33    }
34
35    /// Set whether processes are spawned into a new process group where supported.
36    #[must_use]
37    pub fn with_create_process_group(mut self, create_process_group: bool) -> Self {
38        self.create_process_group = create_process_group;
39        self
40    }
41
42    /// Set whether termination targets descendants through the process group.
43    #[must_use]
44    pub fn with_terminate_descendants(mut self, terminate_descendants: bool) -> Self {
45        self.terminate_descendants = terminate_descendants;
46        self
47    }
48}