Skip to main content

Module spawn_program

Module spawn_program 

Source
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, because posix_spawnp would search the parent’s PATH instead of the child’s;
  • on Apple platforms, a relative program containing / is combined with current_dir, because of a historical posix_spawnp bug.

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§

ChildPath
The PATH the child process will see.

Functions§

command_for_spawn
Create a Command for program that stays on the posix_spawn path when the program can be resolved the way the child would resolve it.
resolve_spawn_program
Resolve program to the absolute executable path the child would run.