-
-
Save MatrixManAtYrService/d25aafb4131a8a14ca2a6d05a3dd88e9 to your computer and use it in GitHub Desktop.
bash parallelism example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
❯ ./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