bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference between EPOCHREALTIME and EPOCHSECONDS


From: Martin Schulte
Subject: Re: Difference between EPOCHREALTIME and EPOCHSECONDS
Date: Tue, 14 Apr 2020 19:43:34 +0200

Hello Chet, hello Felix, hello all!

> > Bash Version: 5.0
> > Patch Level: 16
> > Release Status: release
> > 
> > Description:
> >         Integer part of $EPOCHREALTIME could increase more than 8000
> > microseconds before $EPOCHSECONDS
> 
> It's the difference between time() and gettimeofday().

I didn't believe it ;-) but running

time_gettimeofday.c:
====================
#include <time.h>
#include <sys/time.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
  struct timeval tv;
  time_t t;
  struct timespec sleep;
  sleep.tv_sec = 0;
  sleep.tv_nsec = 1000000;
  for (int i=0; i<1001; i++) {
    gettimeofday(&tv, NULL);
    t = time(NULL);
    printf("%d.%.6d %d %d\n", tv.tv_sec, tv.tv_usec, t, tv.tv_sec-t);
    nanosleep( &sleep, NULL );
  }
  return 0;
}

with 

gcc -o time_gettimeofday time_gettimeofday.c && ./time_gettimeofday |
  egrep '\.(00|99)

shows it is right...

Thanks and best regards,

Martin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]