Expand description
Two-mode process spawning. Free functions only — no module-internal traits.
Modes (only two; the dangerous combination detached + caller-pipes has no
API surface):
spawn_daemon— detached lifetime, sanitized file-or-NUL stdio, sanitized handle list, no console window, ignores parent’s Ctrl-C. The returnedDaemonChilddoes NOT die when dropped.spawn— contained lifetime, caller-controlled stdio viaSpawnStdio, sanitized handle list, no console window by default (opt in viaSpawnStdio::show_console), bounded drain. The returnedSpawnedChildkills the child on Drop.
§Sanitized handle inheritance
Both modes inherit ONLY the three stdio handles we resolve here. On
Windows we use PROC_THREAD_ATTRIBUTE_HANDLE_LIST to whitelist exactly
the resolved handles. On Unix the spawned child runs a pre_exec closure
that walks /proc/self/fd (or /dev/fd) and closes every fd > 2.
Motivation: when a process tree has a pipe-redirected ancestor (Python
subprocess.Popen(stdout=PIPE), IDE language-server hosts, CI runners,
etc.), every intermediate CreateProcessW(bInheritHandles=TRUE) on
Windows — and every fork+exec of a non-O_CLOEXEC fd on Unix —
duplicates that orphaned pipe write-end into the new child. The original
reader at the top never sees EOF.
Issue: https://github.com/zackees/running-process/issues/110.
Structs§
- Daemon
Child - Handle for a detached child that is not terminated when dropped.
- Daemon
Stdio - Caller-supplied output bindings for a detached synchronous child.
- Spawn
Stdio - Caller-supplied stdio bindings for a contained synchronous child.
- Spawned
Child - Handle and optional parent pipe ends for a contained child.
Enums§
- Daemon
Stdio Source - Output destination accepted by the detached-child path.
- Environment
Policy - Selects the base environment used for a newly spawned process.
- Stdio
Source - Standard-stream source or destination for a contained child.
- Sync
Environment - Environment base selected by the shared caller for a synchronous spawn.
Constants§
- DAEMON_
MARKER_ ENV_ VAR - Set on every child spawned through the daemon path, so a process can be recognized as a declared daemon rather than inferred to be one.
Traits§
- Spawned
Child Control - Native control operations for a contained child.
Functions§
- spawn
- Spawn
commandas a contained child with caller-controlled stdio. Sanitized handles, and no console (DETACHED_PROCESSon Windows). Child dies when the returnedSpawnedChildis dropped. - spawn_
daemon - Spawn
commandas a detached daemon. NUL stdio, sanitized handles, no console window, ignores parent’s Ctrl-C / SIGINT (Windows:CREATE_NEW_PROCESS_GROUP+DETACHED_PROCESS; Unix:setsidputs the daemon in a new session so it’s not in the parent’s foreground group). - spawn_
daemon_ breaking_ away_ from_ job - Like
spawn_daemon, but the child also breaks away from any Job Object the spawner belongs to (Windows; a no-op elsewhere). - spawn_
daemon_ breaking_ away_ with_ env_ policy spawn_daemon_breaking_away_from_jobwith an explicit env policy.- spawn_
daemon_ with_ clear_ env - Like
spawn_daemonbut with explicit control over whether the daemon’s inherited env is passed through to the child. - spawn_
daemon_ with_ env_ policy - Spawn a detached daemon using an explicit environment policy.
- spawn_
daemon_ with_ environment - Spawn a daemon using an explicit live environment base.
- spawn_
daemon_ with_ explicit_ environment - Spawn a daemon from a caller-assembled complete environment base.
- spawn_
daemon_ with_ stdio - Spawn a detached daemon with file-or-NUL stdout and stderr.
- spawn_
daemon_ with_ stdio_ and_ env_ policy spawn_daemon_with_stdiowith an explicit environment policy.- spawn_
with_ env_ policy - Spawn a contained child using an explicit environment policy.
- spawn_
with_ environment - Spawn a contained child using an explicit live environment base.
- spawn_
with_ explicit_ environment - Spawn a contained child from a caller-assembled complete environment base.