I understand there is a usleep command in bash. Is this a "busy" or "blocking" sleep? Or will this yield time to other processes?
2 Answers
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.
- 3,036
- 3
- 26
- 52
-
I suspect [unix.se] would be the best fit. – user Oct 04 '16 at 15:42
There is no usleep
command in bash. usleep: command not found
on bash 4.3.11 and nothing like that mentioned in the changelog ...
- 97,248
- 13
- 177
- 225
-
http://serverfault.com/questions/469247/how-do-i-sleep-for-a-millisecond-in-bash-or-ksh/704338#704338?newreg=3f247116a41343b7bd7b134da953b08d – Mechi Fendel Sep 26 '16 at 11:31
-
-
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 '16 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 '16 at 13:21