-1

I understand there is a usleep command in bash. Is this a "busy" or "blocking" sleep? Or will this yield time to other processes?

0

2 Answers 2

4

This probably don't really belong on Server Fault (though I'm not sure which site it would belong on), but here's an answer anyway:

The bash shell does not have a builtin usleep command (nor does it have a builtin sleep command). sleep is a standard program on Unix systems and is available regardless of which shell you're running. usleep appears to be a program that was written by people at RedHat and might only be present in RedHat-related distributions (RHEL and derivatives; Fedora). It doesn't appear to be available in Debian.

In any case, sleep and usleep use the standard sleep() and usleep() system calls, which pause program execution for the specified amount of time[0] (making them "blocking"), and use no CPU time during their sleep (making them not "busy").

[0] The amount of time isn't actually guaranteed to be precisely what was requested, because of the way the kernel scheduler works. The usual guarantee is that it will sleep for at least the requested time. This isn't an issue for integer sleep() durations, because the variance will be much less than a second, but usleep() durations (and fractional sleep() durations) might not end up being exact.

1
1

There is no usleep command in bash. usleep: command not found on bash 4.3.11 and nothing like that mentioned in the changelog ...

4
  • And it works - seems to yield - not block. Sep 26, 2016 at 11:32
  • Then this is not a bash builtin but an external utility. What does which usleep say? Why on earth should it block anyway?
    – Sven
    Sep 26, 2016 at 11:34
  • 1
    usleep appears to be a RH/Fedora utility that only exists in these distributions as part of the initscripts package.
    – Sven
    Sep 26, 2016 at 13:21

Not the answer you're looking for? Browse other questions tagged .