Last active
July 27, 2024 08:14
-
-
Save babarot/37cb04224a2c032313c972e7ea1962fe to your computer and use it in GitHub Desktop.
Wait for a fix number of process in bash
This file contains 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
for i in {1..10} | |
do | |
{ | |
c=$((RANDOM % 6 + 1)) | |
echo "start $c" | |
sleep $c | |
echo "end $c" | |
} & | |
if (( (i % 5) == 0 )); then | |
wait | |
fi | |
done | |
wait |
This file contains 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
cnt=1 # Use counter | |
for i in {1..10} | |
do | |
{ | |
c=$((RANDOM % 6 + 1)) | |
echo "start $c" | |
sleep $c | |
echo "end $c" | |
} & | |
if (( (cnt++ % 5) == 0 )); then | |
wait | |
fi | |
done | |
wait |
Author
babarot
commented
Jul 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment