?
Solved

Delay Function

Posted on 2003-02-24
7
Medium Priority
?
216 Views
Last Modified: 2010-04-21
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?
0
Comment
Question by:yury1854
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:akshayxx
ID: 8014005
use sleep() to sleep for 'seconds'
and usleep() to sleep for "micro seconds"
the delay that sleep gives is quite noticable.
more than 3-4 seconds is rather irritating.
0
 

Author Comment

by:yury1854
ID: 8014047
What do I need to include for usleep()? <time.h> does not seem to have it.
0
 
LVL 8

Accepted Solution

by:
akshayxx earned 150 total points
ID: 8014446
#include <unistd.h>

       void usleep(unsigned long usec);
       int usleep(unsigned long usec); /* SUSv2 */
DESCRIPTION
       The  usleep()  function     suspends execution of the calling
       process for usec microseconds.  The sleep may  be  length-
       ened  slightly by any system activity or by the time spent
       processing the call.

RETURN VALUE
       None (BSD). Or: 0 on success, -1 on error (SUSv2).

ERRORS
       EINTR  Interrupted by a signal.

       EINVAL usec is not  smaller  than  1000000.   (On  systems
           where that is considered an error.)

CONFORMING TO
       BSD  4.3.  The SUSv2 version returns int, and this is also
       the prototype used by glibc 2.2.2.  Only the EINVAL  error
       return is documented by SUSv2.

NOTES
       The  interaction      of  this function with SIGALRM and other
       timer functions such  as      sleep(),  alarm(),  setitimer(),
       nanosleep()  is     unspecified.   This function is obsolete.
       Use nanosleep(2) or setitimer(2) instead.

SEE ALSO
       alarm(2),    getitimer(2),    nanosleep(2),     select(2),
       setitimer(2), sleep(3)

                   2001-04-02               USLEEP(3)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yury1854
ID: 8022382
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.
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8022555
>>>Whenever I request the time in milliseconds or smaller, it give me 0

what function call u make .. ?
0
 

Author Comment

by:yury1854
ID: 8030609
ftime(timeb *);
0
 
LVL 8

Expert Comment

by:akshayxx
ID: 8030740
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question