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
126
127
//! Stop processes gracefully, even on Windows.
//!
//! On Windows this sends real `CTRL_C_EVENT` / `CTRL_BREAK_EVENT` console
//! signals (or closes a GUI window) to an arbitrary process, and can write to
//! its standard input. Unlike the original Go implementation it does not ship
//! and drop a separate "proxy" executable into a temporary folder.
//!
//! Windows can attach a process to only one console at a time, so reaching a
//! foreign console sometimes needs a short-lived detached process. The crate
//! picks the cheapest route automatically:
//!
//! 1. **Direct**: the target shares the caller's console, nothing to attach.
//! 2. **In-process**: the caller has no console, so attach, send, detach.
//! 3. **Helper**: the caller has its own console; a detached helper attaches
//! to the target console instead. By default the helper is *the current
//! executable re-launched with a marker argument*, intercepted before
//! `main` by a C runtime initializer that this crate registers itself. No
//! call from `main` is needed ([`run_helper_if_requested`] exists only for
//! unusual setups). When this code lives in a DLL, point the crate to an
//! executable that links it with [`set_helper`].
//!
//! On Unix it sends POSIX signals and can write to a process' controlling TTY.
//!
//! Set `TERMINATOR_DEBUG=1` to print the chosen route to stderr.
//!
//! # Quick start
//!
//! ```no_run
//! use terminator::{stop, Method};
//! # fn main() -> terminator::Result<()> {
//! stop(1234, Method::CtrlC)?;
//! # Ok(())
//! # }
//! ```
pub use ;
pub use child_tree;
use ;
pub use ;
/// Does nothing on this platform. Exists so cross-platform code can call it
/// unconditionally; see the Windows documentation for the real behavior.
/// A cross-platform way to ask a process to stop.
///
/// POSIX has no equivalent of the Windows console control events or window
/// messages, so there every method sends `SIGINT`.
/// Ask the process with id `pid` to stop using the given [`Method`].
///
/// Returns `Ok(())` once the request was delivered. Delivery does not
/// guarantee the process handled it or exited; use [`wait_for_stop`].
/// Forcibly terminate the process with id `pid`.
///
/// Windows: `TerminateProcess`. POSIX: `SIGKILL`. The process gets no chance
/// to clean up; prefer [`stop`] when a graceful shutdown is possible.
/// Write `msg` to the standard input of the process with id `pid`.
///
/// Useful to answer prompts such as `Terminate batch job (Y/N)?`.
///
/// On Windows the message is injected into the target console's input buffer
/// and must end with `"\r\n"` to be submitted. On Unix it is pushed into the
/// process' controlling terminal with `TIOCSTI`, which usually requires root
/// (and is disabled by some kernels); use `"\n"` on Linux, `"\r"` on macOS.
/// Returns `true` while the process with id `pid` is running.
/// Block until the process `pid` is no longer running or `timeout` elapses
/// (forever if `None`). Returns `true` if the process stopped.