Created
February 29, 2012 16:18
-
-
Save sveneisenschmidt/1942102 to your computer and use it in GitHub Desktop.
Parallel execution of bash scripts
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
#!/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 |
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
#!/bin/bash | |
sleep 10 | |
echo 'slept 10 seconds' |
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
#!/bin/bash | |
sleep 3 | |
echo 'slept 3 seconds' |
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
#!/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