Friday, December 7, 2012

Shell scripting - sleep for milliseconds

Ever tried to make your shell script sleep for milliseconds? I tried, and failed miserably in doing so. I didnt know that decimal numbers are not allowed after the sleep command.

I found the following command that could be used for "virtually simulating" the millisecond sleep command:

typeset -i count=0;
while [[ ${count} -le 5700 ]];
do
      count=${count}+1
done

decrease the value 5700 to a value which would suit your needs. 5700 gives you ~1 sec time.


1 comment:

  1. That is not sleeping, that is delaying. Sleeping pauses ALL execution in the calling program while it waits for an interrupt. PROBABLY, given the speed of modern cpiters, other programs will still get execution time while your code bit is delaying, but it will be degraded access to execution time. Very bad programming or OS design in embedded or real-time systems and irresponsible on desktop or server coding. No offense intended

    ReplyDelete