millisecond delay in C - linux

M

Macgyver

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.
 
R

Robert Frunzke

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

Joona I Palaste

Robert Frunzke said:
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?
 
A

Alex

Macgyver said:
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.
 
R

Robert Frunzke

Alex said:
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
 
F

Floyd Davidson

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.
 
F

Flash Gordon

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.
 
A

August Derleth

Robert said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top