Concurrent Shell Command Queues
A Bash script implements a concurrent command queue using named pipes and xargs, allowing dynamic job submission with bounded parallelism.
summary is enough The article provides a clever Bash queue script, but established tools discussed in comments are more practical.
summary
The author shares a Bash and Zsh implementation of a concurrent command queue using named pipes and background xargs, enabling incremental job submission. While it avoids static batching limitations, it introduces trade-offs like non-streamed output and fragile trap handling. Commenters point out more robust existing utilities like GNU Parallel sem, pueue, or make -j.
key points
- Uses mkfifo and xargs -P to enforce concurrency limits while accepting incremental command submissions.
- Includes defensive exit traps for Bash and Zsh, though it cannot easily return individual job failure codes.
- Commenters highlight more reliable alternatives such as GNU Parallel's sem command, pueue, or make -j.
who should read it
Developers and systems engineers looking to add concurrency to complex Bash scripts without changing languages.
discussion positive
consensus
Commenters appreciate the clever pure-Bash approach but argue that dedicated tools handle edge cases and signal handling much better.
pushback
Some debate the inherent fragility of Bash job control and signal propagation, noting that shell concurrency primitives are notoriously difficult to get right.
> How to run shell commands in parallel while limiting their concurrency.
Depending upon the task, generate a Makefile and run it with:
make -j <concurrency>
> My original use case had to do with making a large number of web requests
This is in fact the use case that caused me to think about using a Makefile for concurrency probably 20 years ago. A rule for downloading each URL to a file. Then a simple `make -j <jobs>` with whatever concurrency I desired and bonus: automatically skipping already downloaded files. e.g.:
BASE := https://example.com/files FILES := a.txt b.txt c.txt d.txt …
Provides a practical alternative using GNU Make (-j) to achieve task concurrency and incremental execution without writing custom queue logic.
Generated by an LLM from the article and thread. Check the sources before relying on it.