[NTLUG:Discuss] Time calculations after uptime > 248.5 days
George E. Lass
George.Lass at osc.com
Wed Jun 14 11:04:04 CDT 2000
Just a quick note to let any interested parties know about
an interesting "glitch" I ran into after my RedHat 5.2
system had been up for more than 0x7fffffff clock ticks....
I use the return value from the "times" call in order to
calculate an "absolute" time stamp (un effected by system
time changes & clock adjustments) for billing information.
In order to convert clock ticks to seconds I was simply doing
a divide by 100:
unsigned long abs_seconds;
struct tms proc_time;
clock_t abs_ticks;
abs_ticks = times(&proc_time); /* get ms since O/S restart */
abs_seconds = abs_ticks / 100; /* convert to seconds */
Once abs_ticks goes beyone 0x7ffffff however, the divide considers
it to be a negative number because clock_t is defined as a "signed
long int". The solution (in my case) was to simply cast abs_ticks
as an unsigned long:
abs_seconds = (unsigned long)abs_ticks / 100; /* convert to
seconds */
--------------------------------------
[root at linux02 /root]# uptime
11:27am up 267 days, 20:28, 7 users, load average: 1.00, 1.00, 1.00
--------------------------------------
I also *had* a RedHat 4.2 system that until 8 days ago had been running
for 497 days, but under 4.2, once the number of clock ticks surpassed
0xffffffff the O/S crashed .......
George
--
... Unix IS a user friendly O/S ...
(It's just picky about its friends)
--ANYTHING FOLLOWING THIS LINE IS NOT THE RESPONSIBILITY OF THE AUTHOR--
More information about the Discuss
mailing list