Skip to content

Instantly share code, notes, and snippets.

@algal
Last active September 13, 2016 21:56
Show Gist options
  • Save algal/e91a7e16f4c18bf45fb6ecee2222a99e to your computer and use it in GitHub Desktop.
Save algal/e91a7e16f4c18bf45fb6ecee2222a99e to your computer and use it in GitHub Desktop.
wallsleep -- like sleep, but uses wall time not process time
#!/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