Get cpu ticks c function
Hello,
I'm looking right now at the man pages for a function/s to get the amount of cpu ticks (i.e milliseconds or whatever) that have elapsed since the machine has started , you know ! also I'm looking for a function that halts process execution for a certain time (as definde in Ms ) , so far I've found sleep() for that matter but it only takes integer as an argument denoting seconds , but I want to be able to halt the execution in the millisecond range (at least that if not even in microseconds , the smaller the time unit the better) so your knowledge is required again. P.s as I said I'm searching how to deal with those two issues but you probably could spare me the time in case you know the answers already and thanks |
To sleep for periods less than a second, use select(), using no file descriptors. See:
Code:
man 2 select Code:
man 2 gettimeofday |
I'm currently working on a cross platform app and was also looking for a milliseconds sleep, in the end I used the following macro which uses usleep which takes microseconds.
Code:
ms_sleep(x) usleep(x*1000) |
Hmmm , thanks for the feedback folks
As wjevans_7d1@yahoo.co has mentioned the issue of NOT having a guarantee that the sleep function does not wait longer than it's supposed is basically the thing that disturbs me the most. Not that I'm a fan of Microsoft or something (those of you who've read some of my posts can assure that I loath it ) but in the regard of programming that involves timing , windows is Unfortunately:rolleyes: much easier . in windows you have sleep() which takes a Millisecond integer and and a function called Getcputicks() (if my memory serves me right) which returns the number of ms's that elapsed since system boot. I wish this issue would be as simple in *nix as it's in windoze :( |
I don't know of a Getcputicks function but there is QueryPerformanceCounter and contrary to what you say about ms it jumps about and is recommended that you double check it with a call to a low resolution timer like timeGetTime and on that matter of windows version of sleep here is some news for you:
http://msdn2.microsoft.com/en-us/library/ms686298.aspx Quote:
|
ahoy
In win32 the sleep() gets the param in milliseconds but here ...
entz, at what exactly are you working on? |
Quote:
but after seeing how unreliable this technique is , despite that it's easy from a theoretical perspective , I've dropped it and went to other methods... cheers |
aha
I understand :)
great :) would you show the open src ;) |
Do
man times Code:
|
All times are GMT -5. The time now is 10:09 PM. |