[Gllug] Clock( ) function in C

Nix nix at esperi.org.uk
Tue Sep 20 17:17:43 UTC 2011


On 20 Sep 2011, Tethys . outgrape:

> On Tue, Sep 20, 2011 at 3:43 PM, dudes dudes <akam123 at hotmail.co.uk> wrote:
>
>> I’m trying to use clock() function (time.h) in milliseconds, but not CPU
>> based. For example do something (some codes) for 5 milliseconds and when it
>> is exactly 5 millisecond, then exit();
>
> You can't do that with standard Linux. All you can do is say "this
> will run for at least 5 milliseconds". If you need precise accuracy,
> in that it must be *exactly* 5ms, you need to use one of the realtime
> Linux variants.

And you wouldn't use clock() for that anyway, you'd use getrusage(), or
timer_gettime() on a timer created with CLOCK_PROCESS_CPUTIME_ID or
CLOCK_THREAD_CPUTIME_ID, possibly passed to a timerfd to enable you to
get interrupt-driven notification of its expiry, or something like that.

-- 
NULL && (void)
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list