sleep#

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

Description#

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.

See also#

alarm, Time::HiRes, select