Expand description
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:
- Direct: the target shares the caller’s console, nothing to attach.
- In-process: the caller has no console, so attach, send, detach.
- 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
mainby a C runtime initializer that this crate registers itself. No call frommainis needed (run_helper_if_requestedexists only for unusual setups). When this code lives in a DLL, point the crate to an executable that links it withset_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
use terminator::{stop, Method};
stop(1234, Method::CtrlC)?;Enums§
- Error
- Something that went wrong while trying to stop or message a process.
- Helper
- Which executable acts as the detached helper when one is required.
- Method
- A cross-platform way to ask a process to stop.
Functions§
- child_
tree - Returns the ids of all descendants of the process
pid, deepest first. - close_
window - Sends
WM_CLOSEtowindow, as if its close button was pressed. - is_
running - Returns
truewhile the process with idpidis running. - kill
- Forcibly terminate the process with id
pid. - main_
window - Returns the main window of process
pid. - run_
helper_ if_ requested - If this process was started as a helper, perform the requested task and exit. Otherwise return immediately.
- send_
message - Write
msgto the standard input of the process with idpid. - set_
helper - Choose which executable is used when a detached helper is required.
- stop
- Ask the process with id
pidto stop using the givenMethod. - wait_
for_ stop - Block until the process
pidis no longer running ortimeoutelapses (forever ifNone). Returnstrueif the process stopped.
Type Aliases§
- Result
- Convenience alias used throughout the crate.
- Window
Handle - Opaque top-level window handle (an
HWNDvalue).