Expand description
Build child commands that Rust’s standard library can launch with
posix_spawn instead of falling back to fork + exec.
fork cost grows with the parent’s address space (page tables and
copy-on-write mappings), so a long-running, memory-heavy agent pays more for
every child it starts. std::process::Command (Rust 1.100) uses
posix_spawnp unless, among other cases:
- the child environment changes
PATH(env_clear()counts) and the program is a bare name, becauseposix_spawnpwould search the parent’sPATHinstead of the child’s; - on Apple platforms, a relative program containing
/is combined withcurrent_dir, because of a historicalposix_spawnpbug.
Resolving the program to an absolute path up front, using the same search
execvp would perform in the child, keeps both cases on posix_spawn
without changing which executable runs or what argv[0] it sees.
Enums§
- Child
Path - The
PATHthe child process will see.
Functions§
- command_
for_ spawn - Create a
Commandforprogramthat stays on theposix_spawnpath when the program can be resolved the way the child would resolve it. - resolve_
spawn_ program - Resolve
programto the absolute executable path the child would run.