Skip to content

Instantly share code, notes, and snippets.

@dwisiswant0
Created April 20, 2021 21:41
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 dwisiswant0/00f125375574b3ebef435fd4d2199345 to your computer and use it in GitHub Desktop.
Save dwisiswant0/00f125375574b3ebef435fd4d2199345 to your computer and use it in GitHub Desktop.
Simple Bash multi-threading
#!/bin/bash
hello() {
echo "Hello, world!"
sleep 3
}
THREAD=5 # define thread
COUNT=1
for i in {1..10}; do
hello &
[[ "${COUNT}" -eq "${THREAD}" ]] && { wait; COUNT=0; } || ((COUNT++))
done
@dwisiswant0
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment