Time/date change issue

I have various processes that need to know how long they’ve been
running. They make use of the clock() function which “returns the
number of clock ticks of processor time used by the program since
it started executing.”

The main application allows the user to change the system date
and time. It does a system call of ‘date’ and ‘rtc’ to change the
date and time.

However, once this is done, the clock() function isn’t doing what
it says it does. The change of the system date/time changes the
value clock() returns, so that it’s no longer the “number of clock
ticks of processor time used by the program since it started
executing”. Its returning that PLUS the difference of any time
adjustments to the system clock. ie. I change the time ahead 1
hour, and clock() starts returning what it should + 3600.

So, the documentation’s wrong, or the clock() function is buggy.
Are there any alternatives that you can suggest? I’d rather
not call ‘date’ and ‘rtc’ with a system() call, so alternatives
to that would be appreciated as well.

In summary, I need to be able to know how long a process has
been running, regardless of time/date changes by the user.

Thanks for the help,
Barry

Barry Robertson <brobertson@softwareremodeling.com> wrote:
: So, the documentation’s wrong, or the clock() function is buggy.
: Are there any alternatives that you can suggest? I’d rather
: not call ‘date’ and ‘rtc’ with a system() call, so alternatives
: to that would be appreciated as well.

Here’s a note that was added a while ago to the Watcom 10.6 docs for clock():

The clock() function simply returns the difference between the
current time and the time the program started, so it gives
incorrect results if the system time changes somewhere
between. The times() function provides more useful information.


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems Ltd.

“Steve Reid” <stever@qnx.com> wrote in message
news:8pqk50$1m0$2@nntp.qnx.com

Barry Robertson <> brobertson@softwareremodeling.com> > wrote:
: So, the documentation’s wrong, or the clock() function is buggy.
: Are there any alternatives that you can suggest? I’d rather
: not call ‘date’ and ‘rtc’ with a system() call, so alternatives
: to that would be appreciated as well.

Here’s a note that was added a while ago to the Watcom 10.6 docs for
clock():

The clock() function simply returns the difference between the
current time and the time the program started, so it gives
incorrect results if the system time changes somewhere
between. The times() function provides more useful information.

and clock() ceils at 2 billions something, around 21 days.


Steve Reid > stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems Ltd.

Mario Charest <mcz@videotron.ca> wrote:
: and clock() ceils at 2 billions something, around 21 days.

Steve McPolin once described clock() as brain-dead. Here’s the other
warning from the docs:

Returns:
The number of clock ticks that have occurred since the program
started executing, or (clock_t) -1 if the time isn’t available or can’t
be represented.


WARNING: The number of clock ticks used to roll over when the maximum
number of ticks was reached (approximately every 49 days).
This was an error in the implementation.

It doesn’t sound like a good function to use for anything important,
does it? :slight_smile:


Steve Reid stever@qnx.com
TechPubs (Technical Publications)
QNX Software Systems Ltd.

Here’s a simple solution.

Attach an interrupt handler to interrupt -1. In the
handler, increment a counter. You can also deal with
overflow if you need to. This interrupt will fire
every 50ms.




Previously, Barry Robertson wrote in comp.os.qnx:

I have various processes that need to know how long they’ve been
running. They make use of the clock() function which “returns the
number of clock ticks of processor time used by the program since
it started executing.”

The main application allows the user to change the system date
and time. It does a system call of ‘date’ and ‘rtc’ to change the
date and time.

However, once this is done, the clock() function isn’t doing what
it says it does. The change of the system date/time changes the
value clock() returns, so that it’s no longer the “number of clock
ticks of processor time used by the program since it started
executing”. Its returning that PLUS the difference of any time
adjustments to the system clock. ie. I change the time ahead 1
hour, and clock() starts returning what it should + 3600.

So, the documentation’s wrong, or the clock() function is buggy.
Are there any alternatives that you can suggest? I’d rather
not call ‘date’ and ‘rtc’ with a system() call, so alternatives
to that would be appreciated as well.

In summary, I need to be able to know how long a process has
been running, regardless of time/date changes by the user.

Thanks for the help,
Barry
\


Mitchell Schoenbrun --------- maschoen@pobox.com