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, 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 to a detached daemon spawned via
spawn_daemon. - Spawn
Stdio - Caller-supplied stdio bindings for
spawn. - Spawned
Child - Handle to a contained child spawned via
spawn.
Enums§
- Stdio
Source - Per-slot source describing what the child should inherit for one of stdin / stdout / stderr.
Functions§
- spawn
- Spawn
commandas a contained child with caller-controlled stdio. Sanitized handles, CREATE_NO_WINDOW. 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_ with_ clear_ env - Like
spawn_daemonbut with explicit control over whether the daemon’s inherited env is passed through to the child.