Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

sleep is a very popular command and we can start sleep from 1 second:

# wait one second please 
sleep 1

but what the alternative if I need to wait only 0.1 second or between 0.1 to 1 second ?

  • remark: on linux sleep 0.XXX works fine , but on solaris sleep 0.1 or sleep 0.01 - illegal syntax
share|improve this question
Can I ask why you want to sleep for 1ms? – Tom O'Connor Jan 15 '13 at 14:03
Yes of course , in my bash script I add "sleep 1" , in some lines , but script run very slowly , so after some conclusion I calculate that sleep 0.1 also bring good results and more faster About the delay , I need delay in order to solve the ssh problem in my bash script , I perform paralel ssh login to some machines by expect and without delay its will not work , As you know from my question the delay should fit both Linux and Solaris – yael Jan 15 '13 at 14:09
Whatever solution you choose, keep in mind that a shell script won't be very accurate in terms of timing. – scai Jan 15 '13 at 14:34
How about doing something that takes a very short time to execute, but does nothing.. like echo "" >/dev/null – Tom O'Connor Jan 15 '13 at 15:01
Good idea but how msec this command take? , I need 0.1 msec , not less then that -:) – yael Jan 15 '13 at 15:12
up vote 31 down vote accepted

Bash has a "loadable" sleep which supports fractional seconds:

$ cd bash-3.2.48/examples/loadables
$ make sleep && mv sleep
$ enable -f sleep


$ which sleep
$ builtin sleep
sleep: usage: sleep seconds[.fraction]
$ time (for f in `seq 1 10`; do sleep 0.1; done)
real    0m1.000s
user    0m0.004s
sys     0m0.004s

The downside is that it may not be provided with your bash binary, so you would need to compile it yourself, as shown (though on Solaris it would not necessarily be as simple as I have shown above).

If that's not suitable, the next easiest thing to do is build or obtain sleep from GNU coreutils, this supports the required feature.

As a last resort you could use perl (or any other scripting that you have to hand) with the caveat that initialising the interpreter may be comparable to the intended sleep time:

$ perl -e "select(undef,undef,undef,0.1);"
$ echo "after 100" | tclsh
share|improve this answer
Ah, since you're using expect you can probably just use "after N", where N is milliseconds, directly in your script. – mr.spuratic Jan 15 '13 at 14:46
use usleep like @Luis Vazquez and @sebix write – Ilan.K Feb 20 at 9:36

The documentation for the sleep command from coreutils says:

Historical implementations of sleep have required that number be an integer, and only accepted a single argument without a suffix. However, GNU sleep accepts arbitrary floating point numbers. See Floating point.

Hence you can use sleep 0.1, sleep 1.0e-1 and similar arguments.

share|improve this answer
see my remark about SOLARIS OS – yael Jan 15 '13 at 13:37
Did you mix up is and isn't? – scai Jan 15 '13 at 13:42
see my update in my quastion – yael Jan 15 '13 at 13:45
Yael, I think there're still one too many negatives in your question; are you sure you mean "not illegal syntax"? – MadHatter Jan 15 '13 at 14:23
for example - I run on solaris 10 this: # sleep 0.1 sleep: bad character in argument , about linux sleep 0.1 works fine – yael Jan 15 '13 at 14:37

Sleep accepts decimal numbers so you can break it down this like:

1/2 of a second

 sleep 0.5

1/100 of a second

sleep 0.01

So for a millisecond you would want

sleep 0.001
share|improve this answer
You can also drop the leading zero before the decimal point. eg. sleep .5 – Mike Causer Jun 22 '14 at 7:13

Try this to determine accuracy:

    time sleep 0.5      # 500 milliseconds (1/2 of a second)
    time sleep 0.001    # 1 millisecond (1/1000 of a second)
    time sleep 1.0      # 1 second (1000 milliseconds)

Combination of mr.spuratic's solution and coles's solution.

share|improve this answer

You may simply use usleep. It takes microseconds (= 1e-6 seconds) as parameter, so to sleep 1 millisecond you would enter:

usleep 1000
share|improve this answer

I had the same problem (no shell usleep on Solaris) so I wrote my own thus:

  #include "stdio.h"
  int main(int argc, char **argv) {
     return 0;

Doesn't check arguments - I'd recommend a properly written one if you wanted to keep it but that (gcc usleep.c -o usleep) will get you out of a hole.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.