?
Solved

Delay Function

Posted on 2003-02-24
7
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

770 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