Bash Named Pipe FIFO Producer-Consumer Pipeline Prompt
Decouple a data producer from one or more consumers across separate processes using a mkfifo named pipe, with correct open/blocking semantics and cleanup
- Target user
- SREs and automation engineers building lightweight inter-process streaming without a message broker
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior automation engineer who specializes in Unix named pipes (FIFOs) and shell concurrency patterns. I will provide: - What the producer emits and how often (e.g. log lines, job ids, metrics) - How many consumers I need and whether each line should go to one consumer or be fanned out - Where the FIFO should live and the user/permissions constraints Your job: 1. **Create the FIFO** — `mkfifo` with an explicit mode, placed in a private directory (`mktemp -d`), and explain why a FIFO differs from a regular file. 2. **Explain blocking on open** — clarify that opening a FIFO for read blocks until a writer appears (and vice versa) and how to avoid a startup deadlock. 3. **Wire the producer** — write to the FIFO with line-buffered output, handling `SIGPIPE`/`EPIPE` when no consumer is attached. 4. **Wire the consumer(s)** — read loop with `while IFS= read -r line; do ... done < "$fifo"`, and show the single-consumer vs. fan-out distinction (one FIFO ≠ broadcast). 5. **Manage lifecycle** — start order, backgrounding with `&`, and how an unexpected reader EOF closes the pipe. 6. **Clean up** — `trap` to `rm -f` the FIFO and kill background readers on EXIT/INT/TERM. Output as: a runnable producer script and consumer script (two code blocks) plus a 3-line "how to launch" note. Warn explicitly that a FIFO delivers each byte to exactly ONE reader — do not present it as a pub/sub broadcast mechanism.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Bash Coprocess Bidirectional Pipe Orchestration Prompt
Drive a long-running interactive child process from a Bash script using a coproc so you can stream commands in and read responses out without re-spawning the process per call
-
Bash xargs Parallel Batch Execution Prompt
Process a large list of items (URLs, files, hosts) concurrently with xargs -P bounded parallelism, with NUL-safe input and correct failure aggregation
-
Python ThreadPoolExecutor I/O Fan-Out Prompt
Parallelize I/O-bound work — HTTP requests, file reads, shell-outs, DB queries — with concurrent.futures.ThreadPoolExecutor, with bounded concurrency, ordered results, error isolation, and clean cancellation.
-
Python Token Bucket Rate Limiter Prompt
Implement a correct, thread-safe (and asyncio-friendly) token bucket rate limiter in Python to throttle outbound API calls, respect provider quotas, and smooth bursts — with tests and a clean decorator/context-manager API.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.