pub struct KillTarget { /* private fields */ }Expand description
A bundle of identifiers for killing a child process.
On Linux, holds a pidfd for race-free direct-child signalling. On other
unix targets, just the raw PID — kills go through kill(pid, sig).
Process-group signals always use the PID as PGID (we set pgid = pid in
the child via setpgid at spawn) and accept the killpg PID-reuse window.
Implementations§
Source§impl KillTarget
impl KillTarget
Sourcepub fn from_child(child: &Child) -> Option<Self>
pub fn from_child(child: &Child) -> Option<Self>
Build a kill target from a freshly spawned tokio::process::Child.
Returns None if the child has no PID (already reaped). On Linux,
attempts to open a pidfd; if that fails (old kernel, permission
denied), the target falls back to PID-based kill — the caller still
gets a usable target, just without the reuse-race protection.
Sourcepub fn from_pid(pid: Pid) -> Self
pub fn from_pid(pid: Pid) -> Self
Build a target from a raw PID (the JC watcher uses this — it can’t borrow the original target across the spawn boundary, so it re-opens). On Linux, a fresh pidfd is opened; if it fails (e.g. the child was reaped between spawn and reopen, leaving the PID free for reuse), returns a target that falls back to PID-based kill — best-effort.
Sourcepub fn signal(&self, sig: Signal)
pub fn signal(&self, sig: Signal)
Send sig to the direct child. On Linux uses pidfd if available
(immune to PID reuse), otherwise falls back to kill(pid, sig).