By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

millisecond delay in C - linux

P: n/a
Hi all,

does anyone know how to generate a millisecond delay in C, compiling
under Linux? I understand the function sleep() will generate a delay
down to a resolution of one second, but I need to be able to refine
this to milliseconds.

Any ideas?

Thanks in advance,

Ben.
Nov 14 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
checkout the select() call - it is often used for such a purpose. or
nanosleep().

Macgyver wrote:
Hi all,

does anyone know how to generate a millisecond delay in C, compiling
under Linux? I understand the function sleep() will generate a delay
down to a resolution of one second, but I need to be able to refine
this to milliseconds.

Any ideas?

Thanks in advance,

Ben.

Nov 14 '05 #2

P: n/a
Robert Frunzke <Ro**************@freenet.de> scribbled the following:
checkout the select() call - it is often used for such a purpose. or
nanosleep().


Which part of the ISO C standard defines either of these functions?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Ice cream sales somehow cause drownings: both happen in summer."
- Antti Voipio & Arto Wikla
Nov 14 '05 #3

P: n/a
"Macgyver" <bh******@dodo.com.au> wrote in message
news:63**************************@posting.google.c om...
does anyone know how to generate a millisecond delay in C, compiling
under Linux? I understand the function sleep() will generate a
delay down to a resolution of one second, but I need to be able to
refine this to milliseconds.


There is no way to do so in standard C, the topic of this newsgroup. The
function sleep() is also not part of standard C. The clue is the fact that
the operating system is relevant.

Try asking in comp.unix.programmer <OT> or man 2 nanosleep </OT>.

Note that you seem to be asking for a way to achieve your solution ("How do
I use a sledgehammer to crack a walnut?"), not for a solution to your
problem ("How do I crack a walnut?"). This may well mean you don't get the
best end result.
Nov 14 '05 #4

P: n/a

Joona I Palaste wrote:
Robert Frunzke <Ro**************@freenet.de> scribbled the following:
checkout the select() call - it is often used for such a purpose. or
nanosleep().

Which part of the ISO C standard defines either of these functions?


Not the ISO C standard. Maybe Posix?
Nov 14 '05 #5

P: n/a

Alex wrote:

Note that you seem to be asking for a way to achieve your solution ("How do
I use a sledgehammer to crack a walnut?"), not for a solution to your
problem ("How do I crack a walnut?"). This may well mean you don't get the
best end result.


He doesnt want to use a sledgehammer (sleep), he wants a finer and
tinyer one (nanosleep) ;)
just kidding,
robert
Nov 14 '05 #6

P: n/a
bh******@dodo.com.au (Macgyver) wrote:
Hi all,

does anyone know how to generate a millisecond delay in C, compiling
under Linux? I understand the function sleep() will generate a delay
down to a resolution of one second, but I need to be able to refine
this to milliseconds.

Any ideas?


Take the advice about asking in a different newsgroup, because
there is *far* more to this than meets the eye.

In fact, you shouldn't ask in comp.unix.programming because the
discussion you need is specific to Linux, not unix in general,
though they won't throw a hissy fit about it like you get here.

Try comp.os.linux.misc or better might be
comp.os.linux.development.apps.

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) fl***@barrow.com
Nov 14 '05 #7

P: n/a
Robert Frunzke wrote:

Joona I Palaste wrote:
Which part of the ISO C standard defines either of these functions?


Not the ISO C standard. Maybe Posix?


1. POSIX isn't C. POSIX is an OS thing that has hooks originally
designed for C.

2. If it isn't ISO C, it's off-topic here. Try comp.programming.unix or
some such.
Nov 14 '05 #8

P: n/a
On Wed, 07 Jan 2004 12:08:57 +0100
Robert Frunzke <Ro**************@freenet.de> wrote:
Joona I Palaste wrote:
Robert Frunzke <Ro**************@freenet.de> scribbled the
following:
checkout the select() call - it is often used for such a purpose. or
nanosleep().

Which part of the ISO C standard defines either of these functions?


Not the ISO C standard. Maybe Posix?


That was Joonas point. This group is about ISO C, the Posix, Unix and
Linux experts hang out in other groups where answers involving these
functions will get properly reviewed for errors.
--
Flash Gordon
Paid to be a Geek & a Senior Software Developer
Although my email address says spam, it is real and I read it.
Nov 14 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.