Expand description
OwnedCommand::inherit_handles_only restricts inheritance to caller handles/fds plus stdio; Windows requires windows_spawn_config for opaque Command settings.
Modules§
- login_
shell - The user’s login-shell PATH and selected environment values, for an app launched from the desktop (Finder, the Dock, a launch agent) that inherits only the session’s minimal environment. Unix only: on Windows every function returns nothing and runs nothing.
- reveal
- Reveal a file or folder in the system file manager, or open it with its default handler,
through
OwnedCommand, and only inside caller-supplied roots.
Structs§
- Ack
- Handed to the watched party; calling
Ack::doneproves it is alive. - Adopted
Identity - A pid together with the start time and executable path that make it a name for exactly one process. See the module documentation.
- Adopted
Process - Breakaway
Denied - The error source returned (inside an
io::Errorof kindPermissionDenied) byOwnedCommand::spawn_uncontained_detached_stricton Windows when the caller’s job object deniesCREATE_BREAKAWAY_FROM_JOB. The OS reports this asERROR_ACCESS_DENIED, which this crate cannot tell apart from other access-denied launch failures; a job that forbids breakaway is the cause this crate expects. - Budget
Labels - Names and scale of the load behind an
IdleObservation, forIdleObservation::result_lines. - Captured
Output - What a capture holds.
- Consecutive
Failures - Cap on restarts granted in a row without the replacement ever reporting ready.
- Cooldown
- Minimum spacing between expensive actions (HeardRight samples stacks at
most once a minute). Pure; the caller supplies
now. - Generation
- Health
Policy - Health
Tracker - Heartbeat
Config - A file another process rewrites as its heartbeat. The watch reads only its modification time, so the writer needs no protocol: a process that keeps touching the file is alive.
- Heartbeat
Watch - A running heartbeat-file watch. Dropping it stops and joins the thread.
- Idle
Observation - What a process did over a quiet window: the idle figures a runtime budget names.
- JobAssignment
Failure - Match
Sweep Options - How
sweep_matchingbehaves. - Match
Sweep Report - The result of
sweep_matching. - Matched
Process - A process that satisfied a
ProcessQuery. - Native
Output Capture - An owned reader of a native child stdout/stderr pipe, with bounded byte retention.
- Output
Capture - A background drain of one output stream into a bounded byte buffer. See the module documentation.
- Owned
Child - Owned
Command - Power
Assertion - A live keep-awake request. Released on drop.
- Process
Entry - One row of the process table.
- Process
Handle - An independent exit reader. On Unix it shares the owner’s cached reap state; on Windows it owns a duplicated process handle, never a borrowed handle value. Keeping this reader alive does not keep an owned process tree alive.
- Process
Query - Which processes to find. All criteria that are set must hold. Built with the methods below; at least one criterion is required.
- Process
Usage - One snapshot of the current process’s resource usage.
- Restart
Permit - Restart
Policy - Restart
Tracker - RunOptions
- Limits for
run. - RunOutput
- What
runobserved. - Stall
Config - Stall
Watchdog - A running watchdog. Dropping it stops and joins the thread.
- Start
Token - When a process started, in the host’s own unit (macOS: seconds and microseconds; Linux: clock ticks since boot and 0; Windows: 100 ns ticks since 1601 and 0). Comparable only on the host that produced it.
- Stderr
Tail - A background drain of one stderr stream. Keeps the most recent lines whose
total size is at most
max_bytes; older lines fall off the front. A single line that alone exceeds the budget is cut to its last bytes, sosnapshotnever returns more thanmax_bytesbytes. - Sweep
Report - The result of
sweep, as pids. - Terminate
AllReport - The result of
terminate_all_owned, as pids. - Termination
Options - Tree
Termination - The result of
OwnedChild::terminate_tree_deep. - Tree
Usage - Resident memory summed over one remembered process and the descendants found while it lived. Members are counted only while their pid-plus-start-time identity still verifies after the table snapshot, so a pid recycled during the scan contributes nothing.
- Unix
Child - A spawned Unix child. The same API as Windows’
WindowsChild: public stdio fields,id,try_wait,waitandkill. It does not expose the stdChild, because a std reap the crate cannot see would make later group signals unsafe (see the module documentation). - Usage
Rates - Rates between two snapshots. Each rate is
Nonewhen either snapshot lacks the counter.
Enums§
- Adopted
Signal - How hard to stop a process. Windows has one way to stop a process, so both are the same there.
- Health
Outcome - Health
Probe - Heartbeat
Event - What a
HeartbeatWatchreports, edge-triggered likeStallEvent. - Identity
Check - What a pid names now, compared with a remembered identity.
- JobAssignment
Mode - Power
Kind - What to keep awake.
- Process
Priority - Scheduling priority requested for the child.
Normal(the default) means “inherit”: it leaves the spawn exactly as it was before this option existed, so the child keeps the parent’s priority class (Windows) or nice value (Unix). It does not reset a lowered parent back to normal. The other values only lower priority, which needs no privilege and never raises a value the child already inherits above a lower one. - Reap
Outcome - Restart
Mode - Restart
Outcome - Signal
Result - The outcome of
AdoptedIdentity::signal. - Stall
Event - Unix
Containment - Wait
Outcome
Constants§
- CREATE_
BREAKAWAY_ FROM_ JOB - The Windows
CREATE_BREAKAWAY_FROM_JOBcreation flag, exposed on every platform so a caller that composes its own flags (for example a deliberately detached replacement process) can OR it in. It asks the new process to leave the creator’s job object; the launch fails with access denied when that job forbids breakaway. - CREATE_
NO_ WINDOW - The Windows
CREATE_NO_WINDOWcreation flag, exposed on every platform so a caller that composes its own flags can OR it in. - DEFAULT_
DROP_ REAP_ TIMEOUT - How long
Dropwaits for a killed leader to be reaped before handing the reap to a background thread. - DEFAULT_
ENV_ ALLOWLIST
Traits§
- NoWindow
- Suppresses the child’s console window on Windows. A no-op elsewhere.
Functions§
- command_
std - A
std::process::Commandforprogramthat already has the no-window flag set on Windows, returned by value so it chains:command_std("git").args(["status"]).output(). Same effect asCommand::new(program)followed byNoWindow::no_window. The async variant istokio_support::command(featuretokio). - find_
processes - Every process that satisfies
query, newest first (children tend to come before the parents that started them). Nothing is signalled. Processes that cannot be inspected (they exited, or belong to another user, or deny access) are skipped, never an error. - launch_
app - Launches the installed app
id: a macOS bundle identifier on macOS, a Windows AppUserModelID on Windows. Other Unix hosts returnUnsupported. - observe_
idle - Sleeps
durationon the calling thread and reports the process’s usage over it. Run it after the load has stopped; it is for benches and tests, so a host readsprocess_usageinstead. - open_
url - Opens
urlwith the handler registered for its scheme (for exampleclaude://). - owned_
count - How many owned children are listed and still alive (their
OwnedChildhas not been dropped). A child that exited but was not dropped is still counted. - process_
group_ exists - Observation-only existence probe for a Unix process group: sends signal 0 and nothing
else.
EPERMmeans members exist that this process may not signal, so the group is present. Group 1 (init’s group) and any id that cannot name a group are refused withInvalidInput;NonZeroU32already excludes 0, which would name this process’s own group. A group holding only zombies whose parent is elsewhere stays present until they are reaped: this is a group observation, not a per-member liveness check (useAdoptedIdentity::is_runningfor a remembered member). - process_
table - Snapshot every process the OS lets this process see.
- process_
usage - Resource usage of the current process, computed now.
- read_
bounded - Reads
readerto its end on the calling thread, keeping the firstmax_bytesbytes. The rest is read and discarded. Use this when the caller can block until the stream closes. - resume_
session - Resumes (
SIGCONT) every process group in sessionsid; same contract assignal_session. Unix only. - run
- Runs
programwithargsto completion or untiloptions.timeout, then returns its status and bounded output. Fails when the program or native output capture cannot start, or lifecycle waiting fails. A non-zero exit is a normalOkwithstatusset. - run_
with_ stdin runwithinputwritten to the child’s stdin. The bytes are written on their own thread while output is drained concurrently, so input larger than a pipe buffer cannot deadlock against a chatty child; the writer closes stdin when done, delivering EOF. A child that exits before consuming the input closes the pipe: that broken-pipe outcome is a normal early exit, not an error, and the child’s status/output are returned as usual. Any other stdin write failure is returned asErrafter the tree is down. A process that outlived the tree and still holds stdin without reading it cannot holdrunpast its deadline: once the tree is down the writer gets a short grace, then it is cancelled (Unix: non-blocking write end; Windows:CancelIoEx) and joined.- signal_
session - Sends
signalto every process group in sessionsid(see [session_groups]). Returnstruewhen at least one group was found and reached. Unix only. Best effort: the groups are found by a process-table scan and signalled by group id, so a group that exits and whose id is reused between the scan and the signal can be hit. Use it for a session the caller created (a pseudo-terminal leader), not for an arbitrary session. - suspend_
current_ process - Suspends the current process with
SIGTSTP(the terminal Ctrl-Z stop), so a shell or TUI can hand the terminal back and resume onSIGCONT. Returns once the process is continued. Unix only. - suspend_
session - Suspends (
SIGSTOP) every process group in sessionsid; same contract assignal_session. Unix only. - sweep
- Stops every process in
targetsthat is still the process it was remembered as: a graceful signal to each, up togracefor them to leave, then a forced signal to those still present. A target whose pid names a different process isrefused, never signalled. Targets are signalled in the order given; pass leaves first (the reverse ofAdoptedIdentity::descendants). - sweep_
descendants sweepofroot’s current descendants, leaves first. The root itself is left alone.- sweep_
matching find_processes, then stop what was found with the identity-checkedsweep(unlessoptionsask for a dry run).- terminate_
all_ owned - Stops every child this process owns (everything started with
OwnedCommand::spawnwhoseOwnedChildhas not been dropped), tree and all, in one call: for an application’s shutdown path, replacing an app-kept list of running children. - tree_
usage TreeUsageforrootand its current descendants (seeAdoptedIdentity::descendantsfor which descendants can be found). A root that is gone or replaced yields an empty usage, not an error. Member figures come from oneprocess_tablesnapshot, then every member is verified again before it is counted.- wait_
process_ group_ empty - Waits at most
timeoutfor a process group to empty;Ok(false)when members remain then. Observation only (seeprocess_group_exists); it never signals the group.