Last active
September 13, 2016 21:56
-
-
Save algal/e91a7e16f4c18bf45fb6ecee2222a99e to your computer and use it in GitHub Desktop.
wallsleep -- like sleep, but uses wall time not process time
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
#!/bin/sh | |
# sleeps for $1 seconds based on wall time, not CPU time | |
set -e | |
# known-good with: | |
# - GNU date (Ubuntu 14.04.3 LTS) | |
# - Darwin date (OS X 10.11.4) | |
wallsleep() { | |
then=$(( $1 + $(date +%s) )) | |
while [ "$(date +%s)" -lt $then ]; do sleep 1; done | |
} | |
if [ "$#" -ne 1 ]; then | |
echo "usage: $(basename $0) seconds" 1>&2 | |
exit 1 | |
fi | |
wallsleep "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment