Repository navigation
fix(jobs): BASHPID in async subshell, jobs -x pgrp, suspend -f - #1152
Merged
Merged
Conversation
…h#1095 #1096 #1097) GNU runs an async `( list )` through a SINGLE make_child fork — the fork IS the subshell (execute_cmd.c:701) — so get_bashpid = getpid() (variables.c:1511) equals the parent's $!. The wrapper spawn already is that fork, but the child re-entered the parens in-process (subshell_depth + 1) and reported pid + 1. The spawn now absorbs the outermost `( list )` (serializing the inner list; guarded on no assignments / no surviving outer redirects or heredoc payloads) and seeds the child's depth plus a BASHPID-origin level via __RUBASH_BG_DEPTH / __RUBASH_BG_BASHPID_BASE, so BASHPID = pid at the spawn-realized level and pid + offset only for deeper in-process levels. This also corrects $BASH_SUBSHELL for async non-paren bodies (`{ }; &`, simple `&` report 1, probed GNU 5.3.20). ID (builtins/jobs.def execute_list_with_replacements `itos (j->pgrp)`; POSIX jobspec -> pgroup). JobEntry records pgrp at fork time (jobs.c:649): first pipeline pid with job control, else the shell's own pgrp (jobs.c:2455-2461; read via getpgid(0) on unix). Bad specs pass through unchanged with the command's own status, per the same GNU function (INVALID_JOB -> continue); `jobs -p`/`-l` already print real pids and are untouched. no-job-control/login guards under -f and stops its own process group (`killpg (shell_pgrp, SIGSTOP)`, builtins/suspend.def), returning SUCCESS once continued. The -f path now does getpgid(0)+killpg(SIGSTOP) on unix (SIGSTOP/SIGCONT ride kernel defaults, never in the managed set); bare `suspend` still reports `cannot suspend: no job control` (rc 1) and non-unix keeps the historical no-op. Verification (bash 5.3.20 oracle vs script files): #1095 child-self == $! and self-TERM rc=143; #1096 prints the pgid; #1097 T-state then rc=0 after CONT — all byte-identical to GNU. Focused suites green: lib 694/694, executor part_035/part_005 (incl. 3 new/rewritten tests), new linux-gated cli suspend test. Full executor_tests shows only the 13 pre-existing Android-environment failures, identical on unmodified origin/master.
caomengxuan666
force-pushed
the
fix/job-trio-clean
branch
from
October 23, 2026 01:12
366f9f5 to
cda7cf4
Compare
Member
Author
|
Rebased onto post-#1181 master and force-pushed as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1095, closes #1096, closes #1097. (1) Async ( ) did a wrapper-spawn plus an in-process parens re-entry, reporting BASHPID=pid+1; now the spawn absorbs the outermost parens (serialized inner list; guarded corners keep the old shape) with __RUBASH_BG_DEPTH/BASHPID_BASE seeding, BASHPID=pid+depth-origin (also fixes async non-paren BASH_SUBSHELL). GNU execute_cmd.c:701 single-fork semantics. (2) jobs -x now substitutes the pgroup id (jobs.c:649, recorded at fork; shell's own pgrp when no job control), bad specs pass through per GNU. (3) suspend -f does killpg(SIGSTOP) on unix (GNU suspend.def), bare suspend still errors rc=1. Tests: lib 694 + new/rewritten executor_tests + linux-gated suspend cli green, executor_tests delta-free vs clean tree; GNU parity (self-kill rc=143 stable, pgid values, suspend T-state) byte-identical.