yury1854
asked on
Delay Function
Hi,
I was wondering if there are any delay or sleep function under linux. I need delays of around several milliseconds. I have tried nanosleep, but that does not seem to work very well and does not give pauses for the desired amounts of time. Whenever I tell it to pause for a few seconds it works more or less, but when I tell it to pause for a large amount on nanoseconds it does not pause at all. Are there any alternatives?
I was wondering if there are any delay or sleep function under linux. I need delays of around several milliseconds. I have tried nanosleep, but that does not seem to work very well and does not give pauses for the desired amounts of time. Whenever I tell it to pause for a few seconds it works more or less, but when I tell it to pause for a large amount on nanoseconds it does not pause at all. Are there any alternatives?
ASKER
What do I need to include for usleep()? <time.h> does not seem to have it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Okay, I've got a weirdness w/ my Linux system then. Whenever I request the time in milliseconds or smaller, it give me 0. This might be because the machine I am trying this on is a P133 w/ Red Hat 5.2. I'll accept the usleep include file as the answer, but if anyone has any suggestions, please tell me. Thank you.
>>>Whenever I request the time in milliseconds or smaller, it give me 0
what function call u make .. ?
what function call u make .. ?
ASKER
ftime(timeb *);
did u try gettimeofday()?
http://unixhelp.ed.ac.uk/CGI/man-cgi?gettimeofday+2
http://unixhelp.ed.ac.uk/CGI/man-cgi?gettimeofday+2
and usleep() to sleep for "micro seconds"
the delay that sleep gives is quite noticable.
more than 3-4 seconds is rather irritating.