Skip to content

Instantly share code, notes, and snippets.

@onokatio
Created July 11, 2020 07:58
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 onokatio/1577870b96723aa99620b4681430e797 to your computer and use it in GitHub Desktop.
Save onokatio/1577870b96723aa99620b4681430e797 to your computer and use it in GitHub Desktop.
#!/bin/bash
function command_1(){
echo "Starting thread 1..."
sleep 5
echo "thread 1 finished."
return 0
}
function command_2(){
echo "Starting thread 2..."
sleep 10
echo "thread 2 finished."
return 0
}
function command_3(){
echo "Starting thread 3..."
sleep 1
echo "thread 3 finished."
return 1
}
export -f command_1
export -f command_2
export -f command_3
jobs=()
jobs+=( "command_1 " )
jobs+=( "command_2 " )
jobs+=( "command_3 " )
echo "${jobs[@]}" \
| xargs -P 0 -n1 bash -c
echo $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment