1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/// Prepare a command so platform-specific signal delivery targets the spawned child *and* any
/// processes it goes on to fork.
///
/// The child is set up as the leader of a new process group (Unix) or its own console process
/// group (Windows). Termination signals are then sent to that group, not the child's PID, so any
/// grandchildren the child fork-execs (a shell wrapper that launches the real binary, a build
/// tool that fans out workers) are signaled together with the leader instead of being orphaned
/// when the leader exits.
///
/// - **Unix:** sets the child's process group to itself (`setpgid(0, 0)` via Tokio's
/// `Command::process_group(0)`), so the child's PID is also its PGID and the group is
/// addressable as `-PGID` in `kill(2)`.
/// - **Windows:** passes `CREATE_NEW_PROCESS_GROUP`, so `GenerateConsoleCtrlEvent` with the
/// child's PID as the process-group ID delivers `CTRL_BREAK_EVENT` to every process in the
/// group.
/// - **Other platforms:** no-op. The crate's termination APIs are gated to Unix and Windows, so
/// spawning still works on other platforms but the resulting child is not set up for
/// group-targeted signal delivery.
pub
/// Send `SIGINT` to the child's process group via `killpg`.
///
/// `SIGINT` is the dedicated user-interrupt signal, distinct from the `SIGTERM` delivered by
/// [`send_terminate`]. Spawns set up the child as the leader of a new process group (see
/// [`prepare_command_for_signalling`]), so the signal reaches any grandchildren the child has
/// forked.
///
/// This is a raw signal sender over `tokio::process::Child`. Callers that can reap process state
/// should do so before using it.
pub
/// Send `SIGTERM` to the child's process group via `killpg`.
///
/// `SIGTERM` is the conventional "asked to terminate" signal sent by service supervisors and the
/// operating system at shutdown. Spawns set up the child as the leader of a new process group
/// (see [`prepare_command_for_signalling`]), so the signal reaches any grandchildren the child
/// has forked.
///
/// This is a raw signal sender over `tokio::process::Child`. Callers that can reap process state
/// should do so before using it.
pub
/// Deliver `CTRL_BREAK_EVENT` to the child's console process group via
/// `GenerateConsoleCtrlEvent`.
///
/// `CTRL_BREAK_EVENT` is the only console control event that can be targeted at a nonzero process
/// group: `CTRL_C_EVENT` requires `dwProcessGroupId = 0` and would be broadcast to every process
/// sharing the calling console (including the parent), so it is not usable to terminate a single
/// child group. There is therefore no separate analogue for `SIGINT` vs. `SIGTERM` on Windows.
///
/// This is a raw signal sender over `tokio::process::Child`. Callers that can reap process state
/// should do so before using it.
pub
/// Sends `signal` to every process in the child's process group on Unix.
///
/// `pid` is the spawned child's PID. Because the child is set up as the leader of a new process
/// group at spawn time, its PID also serves as the PGID. The signal is sent via `killpg`, which
/// translates to `kill(-PGID, signal)` and reaches every member of the group, including any
/// grandchildren the child has fork-execed.
/// Sends `SIGKILL` to every process in the child's process group on Unix.
///
/// Unlike [`tokio::process::Child::start_kill`], which targets only the child's PID, this hits
/// the whole group so grandchildren are not orphaned. The caller is still responsible for reaping
/// the leader's exit status afterwards (e.g. via `wait`).
pub