Sleep command for noninteger time 
Author Message
 Sleep command for noninteger time

Hi
how can i make a process sleep for about .1 seconds?
the sleep command only allows arguments of integer values.

i tried to run dumb for statements where i want to sleep but seems like
the compiler cleverly gets rid of these.

thanks
Don



Mon, 18 Aug 2003 07:12:04 GMT  
 Sleep command for noninteger time
Well, if you are talking about a unix command sleep, the one I saw
doesn't allow for times less then one second or fractions of a second.

You might have an easier time getting an answer to this question in a
newsgroup related to your platform as this kind of command would be
platform specific.

I'll just apologize in advance for all of the messages you're about to
receive from others here who will imply you're an idiot for even asking
this question in this group.

Quote:

> how can i make a process sleep for about .1 seconds?
> the sleep command only allows arguments of integer values.

--
== Eric Gorr ===== http://www.*-*-*.com/ :9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like {*filter*}, are the last refuge of the incompetent... ===


Mon, 18 Aug 2003 07:35:45 GMT  
 Sleep command for noninteger time


Quote:
>Hi
>how can i make a process sleep for about .1 seconds?
>the sleep command only allows arguments of integer values.


there. If that's your platform. They should be the experts on such stuff. I'm
afraid any advice we give here may do you more harm than good. Sorry.

Good luck.

--
Warmest regards.

Optimize only if it runs too slowly or does not fit, spaces instead of tabs.



Mon, 18 Aug 2003 08:47:25 GMT  
 Sleep command for noninteger time

Quote:

> Hi
> how can i make a process sleep for about .1 seconds?
> the sleep command only allows arguments of integer values.

> i tried to run dumb for statements where i want to sleep but seems like
> the compiler cleverly gets rid of these.

sleep() is not a function defined for C.  This means every implementation is
free to implement it or not and in any way
that the implementor wishes.  It is off-topic in comp.lang.c for
which the functions we discuss are either the ones defined for
the language or written (and posted) by the user.


Mon, 18 Aug 2003 08:47:36 GMT  
 Sleep command for noninteger time

[Grr... YATP - yet another top poster]

Quote:

> > how can i make a process sleep for about .1 seconds?
> > the sleep command only allows arguments of integer values.

> Well, if you are talking about a unix command sleep, the one I saw
> doesn't allow for times less then one second or fractions of a second.

command?

The sleep() _function_ is defined in POSIX, which is not part of ISO C. A
Sleep() _function_ is defined in Win32, which is not part of ISO C.

Quote:
> You might have an easier time getting an answer to this question in a
> newsgroup related to your platform as this kind of command would be
> platform specific.

POSIX questions should be answered in comp.unix.programmer. The answer to OP is
different for POSIX and Win32.

Quote:
> I'll just apologize in advance for all of the messages you're about to
> receive from others here who will imply you're an idiot for even asking
> this question in this group.

Ignorant people who doesn't read the FAQ or lurk a periode, make the risk of
getting flamed. Martin Ambuhl should have explain these matters (in detail) more
than once now.

BTW only newbies in clc top-post.

--
Tor <torust AT online DOT no>
http://www.eskimo.com/~scs/C-faq/top.html



Mon, 18 Aug 2003 19:19:08 GMT  
 Sleep command for noninteger time

Quote:

> how can i make a process sleep for about .1 seconds?
> the sleep command only allows arguments of integer values.

sleep() isn't even ISO. You can't do this in ISO C; you can't even sleep
a whole number of seconds in ISO C. You could hack up a function using
time() or clock(), but their precision isn't guaranteed. However, if
your compiler has sleep() as an extension, this link to the FAQ (which
you should have read before posting, tsk, tsk!) might well be helpful:
<http://www.eskimo.com/~scs/C-faq/q19.37.html>.

Quote:
> i tried to run dumb for statements where i want to sleep but seems like
> the compiler cleverly gets rid of these.

I should hope so. I don't want to have to micro-optimise myself, that's
what compilers are for.

Richard



Mon, 18 Aug 2003 19:06:18 GMT  
 Sleep command for noninteger time

Quote:

> Hi
> how can i make a process sleep for about .1 seconds?
> the sleep command only allows arguments of integer values.

My sleep() does it snoring in milliseconds, in which case it is not a
problem to sleep for 0.1 sec. Are you sure that your system sleeps in
seconds?

Anyhow, to discourage discussion on the non-topicality of this reply,
you can of course also write your own sleep() using the standard ISO-C
clock() function:

#include <time.h>

void iso_sleep(float secs)   /* untested */
{
clock_t cticks = clock() + (clock_t) (secs * CLK_TCK);

  while (clock() < cticks);

Quote:
}

Of course, if you're programming a magnetron or some obscure embedded
system, clock might not behave like expected and return -1 :)

willem  (pre ISO)



Mon, 18 Aug 2003 20:40:03 GMT  
 Sleep command for noninteger time

Quote:


> > how can i make a process sleep for about .1 seconds?
> > the sleep command only allows arguments of integer values.

> My sleep() does it snoring in milliseconds, in which case it is not a
> problem to sleep for 0.1 sec. Are you sure that your system sleeps in
> seconds?

> Anyhow, to discourage discussion on the non-topicality of this reply,
> you can of course also write your own sleep() using the standard ISO-C
> clock() function:

But on a system which has sleep(), you probably don't want to, because
it's a busy-loop and therefore very likely to make you very intimately
aware of the meaning of the acronym LART. IOW, don't do that, it pisses
your sysadmin off.
On an MS-DOS computer, it might work. Even so, it's not even guaranteed
to give a very precise measurement: CLOCKS_PER_SEC (_not_ CLK_TCK, by
the way, that's muchly not standard) may be, say, 100, but that doesn't
guarantee that clock() changes every centisecond. It might cheat, and
change every second, with steps of 100. That would not be a very good
implementation, but MS-DOS's standard clock _isn't_ very good.

Richard



Mon, 18 Aug 2003 20:49:22 GMT  
 Sleep command for noninteger time

Quote:


> > Hi
> > how can i make a process sleep for about .1 seconds?
> > the sleep command only allows arguments of integer values.

[...]

Quote:
> Anyhow, to discourage discussion on the non-topicality of this reply,
> you can of course also write your own sleep() using the standard ISO-C
> clock() function:

> #include <time.h>

> void iso_sleep(float secs)   /* untested */
> {
> clock_t cticks = clock() + (clock_t) (secs * CLK_TCK);

>   while (clock() < cticks);
> }

That doesn't look ISO C to me!  :-)

Anyway your function does not sleep real-time, which is what I expect for this
type of fuctions.

--
Tor <torust AT online DOT no>



Mon, 18 Aug 2003 21:00:29 GMT  
 Sleep command for noninteger time

Quote:
>Anyhow, to discourage discussion on the non-topicality of this reply,
>you can of course also write your own sleep() using the standard ISO-C
>clock() function:

Nope, you can't.

Quote:
>#include <time.h>

>void iso_sleep(float secs)   /* untested */
>{
>clock_t cticks = clock() + (clock_t) (secs * CLK_TCK);

                                              ^^^^^^^
There is no such thing in standard C.  Even if your system has it, it
may be completely unrelated to the value returned by clock.  E.g. on the
system I'm typing this post, CLK_TCK is defined as 60, while clock()
returns the CPU time in microseconds.

Quote:
>  while (clock() < cticks);
>}

Apart from being broken by implementation, your function is also brain
dead by design (a "feature" inherited from its author ;-)  clock()
returns the CPU time used by the current program.  On a busy system,
your function may "sleep" N times longer than requested.

Quote:
>Of course, if you're programming a magnetron or some obscure embedded
>system, clock might not behave like expected and return -1 :)

Freestanding implementations need not provide *any* of the standard C
library functions.  So, rather than having a non-working clock(), it's
more likely that you won't have a clock() at all.

Quote:
>willem  (pre ISO)

The first C standard was adopted about 12 years ago.  If you can't be
bothered to update your C knowledge, please do yourself and the rest of us
a favour and go away: this newsgroup is definitely not for you.

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Mon, 18 Aug 2003 23:19:17 GMT  
 Sleep command for noninteger time

Quote:

> willem veenhoven writes:
> >willem  (pre ISO)

> The first C standard was adopted about 12 years ago. If you can't be
> bothered to update your C knowledge, please do yourself and the rest
> of us a favour and go away: this newsgroup is definitely not for you.

I kindly urge you, Mr. Pop, to refrain from such insults. I know you
consider yourself to be the self-proclaimed chairman of the strict ISO
movement within clc, but frankly I really do not see any humour in your
remark. Go have a beer if you're feeling itchy ...

willem



Tue, 19 Aug 2003 00:24:08 GMT  
 Sleep command for noninteger time


Quote:


> > > Hi
> > > how can i make a process sleep for about .1 seconds?
> > > the sleep command only allows arguments of integer values.

> [...]

> > Anyhow, to discourage discussion on the non-topicality of this reply,
> > you can of course also write your own sleep() using the standard ISO-C
> > clock() function:

> > #include <time.h>

> > void iso_sleep(float secs)   /* untested */
> > {
> > clock_t cticks = clock() + (clock_t) (secs * CLK_TCK);

> >   while (clock() < cticks);
> > }

> That doesn't look ISO C to me!  :-)

Looks fairly valid to me, what's wrong with it?

Quote:
> Anyway your function does not sleep real-time, which is what I expect for
this
> type of fuctions.

"real-time"?

Tom



Tue, 19 Aug 2003 00:46:45 GMT  
 Sleep command for noninteger time


Quote:
>> "real-time"?

>clock() measures a process's CPU time, not wall clock time.

You mean I don't have to point my monitor at my wall clock when I use this
function? That's going to make life a bit easier for me... yes indeed. Now if
I could only figure out why the monitor won't scan my documents...

:-)



Tue, 19 Aug 2003 00:57:20 GMT  
 Sleep command for noninteger time

Quote:



> > > void iso_sleep(float secs)   /* untested */
> > > {
> > > clock_t cticks = clock() + (clock_t) (secs * CLK_TCK);

> > >   while (clock() < cticks);
> > > }
> > Anyway your function does not sleep real-time, which is what I expect for
> this
> > type of fuctions.

> "real-time"?

clock() measures a process's CPU time, not wall clock time.
--
"I should killfile you where you stand, worthless human." --Kaz


Tue, 19 Aug 2003 00:51:09 GMT  
 Sleep command for noninteger time

Quote:


> > willem veenhoven writes:

> > >willem  (pre ISO)

> > The first C standard was adopted about 12 years ago. If you can't be
> > bothered to update your C knowledge, please do yourself and the rest
> > of us a favour and go away: this newsgroup is definitely not for you.

> I kindly urge you, Mr. Pop, to refrain from such insults.

You think that's an insult? You obviously didn't read the rest of that
post for comprehension, then. The above is merely a statement of fact.

Quote:
> I know you
> consider yourself to be the self-proclaimed chairman of the strict ISO
> movement within clc,

There is no such movement (and Dan would not _quite_ be chairman of it
if there were); _all_ of c.l.c is strict ISO, because that's the topic
of c.l.c: ISO C.

Richard



Tue, 19 Aug 2003 00:48:06 GMT  
 
 [ 26 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Header for sleep command

2. I need a DOS version of UNIX sleep command

3. Help with sleep command

4. Sleep command and suspend

5. sleeping for time under the millisecond

6. Any time limit for sleep?

7. Sleeping for times accurat to a microsecond under NT

8. interrupt sleep() or successive sleeps

9. Q: How to set Sleep() between Sleep(0) and Sleep(1)?

10. command line build fails Second time using CreateProcess

11. can I use command line to launch internet explorer and open one url each time

12. ANSI C command to get system time?

 

 
Powered by phpBB® Forum Software