Connect with Expertise | Find Experts, Get Answers, Share Insights

millisecond delay in C - linux

Macgyver
 
Posts: n/a
#1: Nov 14 '05
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.

Robert Frunzke
 
Posts: n/a
#2: Nov 14 '05

re: millisecond delay in C - linux


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



Macgyver wrote:[color=blue]
> 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.[/color]
Joona I Palaste
 
Posts: n/a
#3: Nov 14 '05

re: millisecond delay in C - linux


Robert Frunzke <Robert.no.spam.F@freenet.de> scribbled the following:[color=blue]
> checkout the select() call - it is often used for such a purpose. or
> nanosleep().[/color]

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

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

re: millisecond delay in C - linux


"Macgyver" <bhalicki@dodo.com.au> wrote in message
news:63cd0f02.0401070235.3f182b4b@posting.google.c om...[color=blue]
> 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.[/color]

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.


Robert Frunzke
 
Posts: n/a
#5: Nov 14 '05

re: millisecond delay in C - linux



Joona I Palaste wrote:[color=blue]
> Robert Frunzke <Robert.no.spam.F@freenet.de> scribbled the following:
>[color=green]
>>checkout the select() call - it is often used for such a purpose. or
>>nanosleep().[/color]
>
>
> Which part of the ISO C standard defines either of these functions?
>[/color]

Not the ISO C standard. Maybe Posix?
Robert Frunzke
 
Posts: n/a
#6: Nov 14 '05

re: millisecond delay in C - linux



Alex wrote:[color=blue]
>
> 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.
>[/color]

He doesnt want to use a sledgehammer (sleep), he wants a finer and
tinyer one (nanosleep) ;)


just kidding,
robert
Floyd Davidson
 
Posts: n/a
#7: Nov 14 '05

re: millisecond delay in C - linux


bhalicki@dodo.com.au (Macgyver) wrote:[color=blue]
>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?[/color]

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) floyd@barrow.com
August Derleth
 
Posts: n/a
#8: Nov 14 '05

re: millisecond delay in C - linux


Robert Frunzke wrote:
[color=blue]
>
> Joona I Palaste wrote:[color=green]
>> Which part of the ISO C standard defines either of these functions?
>>[/color]
>
> Not the ISO C standard. Maybe Posix?[/color]

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.


Flash Gordon
 
Posts: n/a
#9: Nov 14 '05

re: millisecond delay in C - linux


On Wed, 07 Jan 2004 12:08:57 +0100
Robert Frunzke <Robert.no.spam.F@freenet.de> wrote:
[color=blue]
> Joona I Palaste wrote:[color=green]
> > Robert Frunzke <Robert.no.spam.F@freenet.de> scribbled the
> > following:
> >[color=darkred]
> >>checkout the select() call - it is often used for such a purpose. or
> >>nanosleep().[/color]
> >
> >
> > Which part of the ISO C standard defines either of these functions?
> >[/color]
>
> Not the ISO C standard. Maybe Posix?[/color]

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.
Closed Thread

Tags
delay c, delay linux