Skip to content

Commit 92e65e1

Browse files
sjarmakclaude
andcommitted
fix: use wait -n to reap zombie subshells in parallel job pool
kill -0 returns success for zombie processes (completed but not yet reaped). Without wait -n, _PIDS never shrinks below PARALLEL_TASKS after all initial slots fill — remaining tasks never get submitted. wait -n on the PIDS list blocks until one child completes and reaps it, allowing kill -0 to correctly detect the freed slot. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 90eae1a commit 92e65e1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

configs/run_selected_tasks.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,19 @@ is_task_completed() {
307307
# ============================================
308308
declare -a _PIDS=()
309309

310-
# Block until fewer than PARALLEL_TASKS jobs are running
310+
# Block until fewer than PARALLEL_TASKS jobs are running.
311+
# Uses wait -n to reap zombies (kill -0 sees zombies as alive; without reaping,
312+
# slots never free even after child processes complete).
311313
_wait_for_slot() {
312314
while [ "${#_PIDS[@]}" -ge "${PARALLEL_TASKS}" ]; do
315+
# Reap any completed child (non-blocking: wait for exactly one child to finish)
316+
wait -n "${_PIDS[@]}" 2>/dev/null || true
317+
# Rebuild PID list, excluding any that are no longer alive
313318
local new_pids=() p
314319
for p in "${_PIDS[@]}"; do
315320
kill -0 "$p" 2>/dev/null && new_pids+=("$p")
316321
done
317322
_PIDS=("${new_pids[@]}")
318-
[ "${#_PIDS[@]}" -ge "${PARALLEL_TASKS}" ] && sleep 2
319323
done
320324
}
321325

0 commit comments

Comments
 (0)