Skip to content

Instantly share code, notes, and snippets.

@sveneisenschmidt
Created February 29, 2012 16:18
Show Gist options
  • Save sveneisenschmidt/1942102 to your computer and use it in GitHub Desktop.
Save sveneisenschmidt/1942102 to your computer and use it in GitHub Desktop.
Parallel execution of bash scripts
#!/bin/bash
declare -a status=()
declare -a threads=(
[0]='sh ./thread-sleep-5.sh'
[1]='sh ./thread-sleep-10.sh'
[2]='sh ./thread-sleep-3.sh'
)
date
for (( i = 0 ; i < ${#threads[@]} ; i++ ))
do
${threads[$i]} &
status[$i]=$!
done
for (( i = 0 ; i < ${#status[@]} ; i++ ))
do
wait ${status[$i]}
done
date
# Output
#Mi 29. Feb 17:09:55 CET 2012
#slept 3 seconds
#slept 5 seconds
#slept 10 seconds
#Mi 29. Feb 17:10:05 CET 2012
#!/bin/bash
sleep 10
echo 'slept 10 seconds'
#!/bin/bash
sleep 3
echo 'slept 3 seconds'
#!/bin/bash
sleep 5
echo 'slept 5 seconds'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment