Skip to content

Instantly share code, notes, and snippets.

@MatrixManAtYrService
Last active May 6, 2019 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatrixManAtYrService/d25aafb4131a8a14ca2a6d05a3dd88e9 to your computer and use it in GitHub Desktop.
Save MatrixManAtYrService/d25aafb4131a8a14ca2a6d05a3dd88e9 to your computer and use it in GitHub Desktop.
bash parallelism example
#! /usr/bin/env bash
bg_process()
{
sleep 1
for i in a b c d e f g h i j k l m n o p
do
echo $i
sleep 1
done
}
rm -f log
rm -f pid
( bg_process & echo $! > pid ) | tee log &
until [ -f log ]
do
sleep 0.5
done
( tail -f -n0 log & ) | grep -q h 1> /dev/null
echo booya
( tail -f -n0 log & ) | grep -q m 1> /dev/null
kill -9 $(cat pid)
❯ ./go
a
b
c
d
e
f
g
h
booya
i
j
k
l
m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment