Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sleep

Suspends execution for the specified number of seconds.

Causes the process to sleep for the given number of whole seconds. Returns the number of seconds actually slept, which may be less than requested if a signal interrupted the sleep.

If Time::HiRes::sleep has been imported into the current package, fractional seconds are supported and the override is used instead. Time::HiRes::sleep dies on negative values.

Without arguments, sleeps indefinitely (until a signal arrives). Negative values are clamped to 0.

Uses libc::sleep() (not std::thread::sleep) so that signals like SIGALRM can interrupt the sleep. If interrupted, any pending $SIG{...} handler is dispatched synchronously before returning.

Synopsis

my $slept = sleep(5);    # pause 5 seconds, returns 5
sleep;                   # sleep forever (until signal)
# with: use Time::HiRes qw(sleep);
sleep(0.5);              # fractional seconds

See Also

alarm, Time::HiRes, select