Created
July 14, 2018 16:04
-
-
Save laser/8239df140178bdc7891754f2629e59d6 to your computer and use it in GitHub Desktop.
fork/join shell
This file contains hidden or 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
echo "" | |
echo "$(date "+%T") 'fork' a process..." | |
# opens the file as input fd 666 before the background job (curl) is started | |
exec 666< <(curl -s 'http://www.fakeresponse.com/api/?sleep=4') | |
echo "" | |
echo "$(date "+%T") 'fork' second process..." | |
# opens the file as input fd 666 before the background job (curl) is started | |
exec 777< <(curl -s 'https://cdn.bringatrailer.com/wp-content/uploads/2017/09/59c4506ce4ca8_P6155050-e1506103879707.jpg') | |
echo "" | |
echo "$(date "+%T") do something else in the meantime (like generate a 32 char random string)..." | |
RANDOM_STR_A=$(date +%s | md5 | base64 | head -c 32 ; echo) | |
echo "" | |
echo "$(date "+%T") blocks until image is downloaded..." | |
gzip <&777 > /tmp/datsun.jpg.gz | |
echo "" | |
echo "$(date "+%T") block until the slow web service responds..." | |
# 3.6 Redirections | |
# 3.6.8 Duplicating File Descriptors | |
# - the < redirection refers to standard input | |
# - cat does not return until fd 666 is closed | |
# - fd 666 is closed when curl completes | |
WEB_SVC_RESP=$(cat <&666) | |
echo "" | |
echo "$(date "+%T") yadda yadda..." | |
echo "RANDOM_STR_A=${RANDOM_STR_A}" | |
echo "WEB_SVC_RESP=${WEB_SVC_RESP}" | |
echo "" | |
echo "$(date "+%T") done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment