[uClibc] clock() for long-running process

Manuel Novoa III mjn3 at codepoet.org
Tue May 11 13:18:28 UTC 2004


On Tue, May 11, 2004 at 03:04:38PM +0200, Joakim Tjernlund wrote:
> > If you're trying to measure elapsed wall clock time on linux and you need
> > only second accuracy, you can use the difference in system uptime.
> > 
> >   #include <sys/sysinfo.h>
> > 
> >   /* Return system uptime in seconds. */
> > 
> >   long uptime(void)
> >   {
> >     struct sysinfo info;
> > 
> >     sysinfo(&info);
> > 
> >     return info.uptime;
> >   }
> 
> OK, thanks. Hmm, why is info.uptime a long instead of an unsigned long? What happens when
> info.uptime reaches negative values? I would guess that uptime just keeps counting until
> it wraps to 0?

No idea.  But even the minimum allowed value for LONG_MAX is a bit over
68 years of seconds.  So I really doubt you need to worry about wrapping
here.  :-)

Manuel



More information about the uClibc mailing list