How to do it...

To start this exercise, we will introduce two terms: leader and follower, or master and worker. In this case, the master (the central host) will create the workers (or minions). While the recipe is a bit contrived, it should make for an easy go-to template for a simple named pipes or FIFO pattern. Essentially, there is a master that creates five workers, and those newly created workers echo out what is provided to them through the named pipe:

  1. To get started, open a new terminal and create two new scripts: master.sh and worker.sh.
  2. In master.sh, add the following contents:
#!/bin/bashFIFO_FILE=/tmp/WORK_QUEUE_FIFOmkfifo "${FIFO_FILE}"NUM_WORKERS=5I=0while [ $I -lt $NUM_WORKERS ]; do  bash worker.sh "$I" &  I=$((I+1))done I=0 ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.