SLEEP(1) | General Commands Manual | SLEEP(1) |
sleep
—
sleep |
seconds |
sleep
utility suspends execution for a minimum of
seconds seconds, then exits. It is usually used to
schedule the execution of other commands (see
EXAMPLES below).
Note: The NetBSD
sleep
command will accept and honor a non-integer
number of specified seconds. Note however, that if the request is for much
more than 2.5 hours, any fractional seconds will be ignored. Permitting
non-integral delays is a non-portable extension, and its
use will decrease the probability that a shell script will execute properly
on another system.
When the SIGINFO
signal is received, an
estimate of the number of seconds remaining to sleep is printed on the
standard output.
sleep
utility exits with one of the following
values:
(sleep 1800; sh command_file
>errors 2>&1)&
This incantation would wait half an hour before running the script command_file. (See the at(1) utility).
To repeatedly run a command (using csh(1)):
while (1) if (! -r zzz.rawdata) then sleep 300 else foreach i (*.rawdata) sleep 70 awk -f collapse_data $i >> results end break endif end
The scenario for a script such as this might be: a program
currently running is taking longer than expected to process a series of
files, and it would be nice to have another program start processing the
files created by the first program as soon as it is finished (when
zzz.rawdata
is created). The script checks every
five minutes for the file zzz.rawdata
. When the file
is found, processing the generated files (*.rawdata
)
is done courteously by sleeping for 70 seconds in between each awk job.
To wait until a particular time, the following, with some error checking added, might be used (using sh(1) on NetBSD):
END=$(( $( date -d "$1" +%s ) - START_TIME )) while [ "${SECONDS}" -lt "${END}" ] do sleep "$((END - SECONDS))" done
where the argument ‘$1
’
specifies the desired date and time in any format the
-d
option to the
date(1) command accepts.
sleep
command is expected to be
IEEE Std 1003.2 (“POSIX.2”) compatible.
sleep
utility appeared in
Version 4 AT&T UNIX. Processing fractional
seconds, and processing the seconds argument respecting
the current locale, was added in NetBSD 1.3. The
ability to sleep for extended periods appeared in NetBSD
9.0.
sleep
command cannot handle requests for durations
much longer than about 250 billion years. Any such attempt will result in an
error, and immediate termination. It is suggested that when there is a need
for sleeps exceeding this period, the sleep
command be
executed in a loop, with each individual sleep
invocation limited to 200 billion years approximately.
January 26, 2019 | NetBSD 10.99 |