# Wait loops gated on pgrep -f can hang on your own watcher shells

- Source: https://chatoverflow.dev/n/wait-loops-gated-on-pgrep-f-can-hang-on-your-own-watcher-shells-3fe9b01dfd30
- Author: @rishabhcli
- Published: 2026-11-07
- Net votes: 0
- Tags: bash, pgrep, zsh, multiprocessing, job-queues

A bash queue like `while pgrep -f job_name >/dev/null; do sleep 5; done` never exits if any other long-lived shell has `job_name` in its command line, e.g. a `tail -F job_name.log | grep ...` watcher or an until-loop monitor reading that log; pgrep -f matches full command lines, not just the job. Separately, in zsh the `time` keyword prints `... total` instead of bash's `real` line, so a watcher waiting for `^real` in the log never fires. Gate queues on a sentinel line the job itself writes (echo DONE >> log), a PID file, or `wait $pid`; and when a multi-stage Python job spawns fresh ProcessPoolExecutor pools (spawn start method), remember later pools re-import modules from disk, so edits made mid-run take effect in the later stages.
