Hi all,
I noticed that the seconds returned by the getutxent() call are not the
same as what's listed as the btime in /proc/stat on the two Linux
systems I've tested on. The getutxent call always returns a higher
value.
At home, I thought for sure that it was adding the jiffies from the
khubd process (since it was the only one that had a number of jiffies,
converted to seconds, equal to the difference I was detecting). At
work, however, that doesn't seem to be the case, as I can't find a
process that has a jiffy count that would account exactly for the
difference (and yes, the CLK_TCK rate is the same on both machines -
100).
I was only able to find one other post that mentions a bug in getutxent
(and getutent) on Linux, but no real details. Does anyone have any more
details on this?
Thanks in advance.
Regards,
Daniel Berger
PS - A short C program provided below for your convenience
/*****************************
* Get the boot time (btime)
*****************************/
#include <utmpx.h>
#include <time.h>
#include <stdio.h>
#ifndef CLK_TCK
#define CLK_TCK sysconf(_SC_CLK_TCK)
#endif
int main()
{
struct utmpx *u;
long seconds;
while((u = getutxent()))
if(u->ut_type == BOOT_TIME)
{
seconds = u->ut_tv.tv_sec;
printf("Clock tick: %li\n", CLK_TCK);
printf("Boot seconds: %li\n",seconds);
break;
}
}
return 0;
/*
My results:
frank-/home/djberge/Programming/C-1683>./btime
Clock tick: 100
Boot seconds: 1019658207
frank-/home/djberge/Programming/C-1684>cat /proc/stat | grep btime
btime 1019658072
frank-/home/djberge/Programming/C-1685>
*/