A process limit binds before the child runs
A grant’s process budget is a property of the Launch, applied inside each
platform’s spawn, so a child under a grant never runs without it.
Command::prepare (core/src/shell/exec/command.rs) sets it behind
one gate, has_active_capabilities, by Launch::limit_resources
(core/src/process/limits.rs); nothing is applied to the child afterward.
- macOS applies it in
pre_exec. The launch’s one hook (ChildSetup::install) applies the session’sChildLimitssoft ceilings first and the grant’s after them, whatever order they were configured in; the grant’s set soft and hard together and so win. The budget is a fork limit measured in the parent, in the child’sRLIMIT_NPROC(Darwin compares a process count with the forking process’s own limit, so it refuses the child’s descendants and no other process of the user’s); a budget that cannot be measured refuses the launch at build. - Linux sets no process budget.
limit_resourcesthere turns core dumps off and nothing else; the process budget is the other platforms’. - Windows applies it in the suspended job assignment, under the groups
lock. The limit is set on the Job Object (a pipeline member’s, or one made
for the child alone) before the child, created suspended, enters it and is
resumed, by
set_active_process_limit, which holdsGROUPSacross its read-modify-write of the job’s oneLimitFlagsword. A write outside the lock could stripKILL_ON_JOB_CLOSEoff a group’s job. - A budget that cannot be set refuses the launch (
unbudgeted, anErrorofunavailable’s wording: “this command would run with no process budget”): on macOS at build, on Windows at the spawn, asUnstarted::Refused. The alternative is a command that runs with no budget while saying it has one.
Why. A limit applied after the spawn leaves a window in which the child runs uncapped, and it needs a second code path per platform to close it, each with its own failure to handle. A limit that is part of the launch is applied where the child is born, by the same code that makes it, and a failure to apply it is the launch’s failure.
See two-enforcers, a-child-lands-once and an-external-end-to-end.